CalendarModel QML Type

A calendar model. 更多...

import 语句: import QtQuick.Controls

特性

方法

详细描述

CalendarModel provides a way of creating a range of MonthGrid instances. It is typically used as a model for a ListView that uses MonthGrid as a delegate.

ListView {
    id: listview
    width: 200; height: 200
    snapMode: ListView.SnapOneItem
    orientation: ListView.Horizontal
    highlightRangeMode: ListView.StrictlyEnforceRange
    model: CalendarModel {
        from: new Date(2015, 0, 1)
        to: new Date(2015, 11, 31)
    }
    delegate: MonthGrid {
        width: listview.width
        height: listview.height
        month: model.month
        year: model.year
        locale: Qt.locale("en_US")
    }
    ScrollIndicator.horizontal: ScrollIndicator { }
}
					

除了 index property, a list of model data roles are available in the context of each delegate:

model.month : int The number of the month
model.year : int The number of the year

Calendar-related types in Qt Quick Controls use 0-based month numbers, like the JavaScript Date objects. However, this differs from QDate , where the months are numbered starting from 1.

To avoid confusion, you can use the following enumeration values:

常量 描述
Calendar.January January (0)
Calendar.February February (1)
Calendar.March March (2)
Calendar.April April (3)
Calendar.May May (4)
Calendar.June June (5)
Calendar.July July (6)
Calendar.August August (7)
Calendar.September September (8)
Calendar.October October (9)
Calendar.November November (10)
Calendar.December December (11)

另请参阅 MonthGrid and Calendar .

特性文档编制

from : date

This property holds the start date.

to : date

This property holds the end date.

方法文档编制

int indexOf ( Date date )

Returns the model index of the specified date .

int indexOf ( int year , int month )

Returns the model index of the specified year and month .

int monthAt ( int index )

Returns the month number at the specified model index .

int yearAt ( int index )

Returns the year number at the specified model index .