CalendarModel QML Type

日历模型更多

Import Statement: import QtQuick.Controls

属性

方法

详细说明

CalendarModel 提供了一种创建一系列MonthGrid 实例的方法。它通常用作ListView 的模型,该 使用MonthGrid 作为委托。

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 属性外,每个委托的上下文中还提供了一系列模型数据角色:

model.month: int月份的数字
model.year: int年的编号

Qt Quick Calendar 模块使用基于 0 的月份数字,以便与 QML 语言使用的 JavaScript Date 类型保持一致。这意味着Date::getMonth() 可以原样传递给方法。在直接处理月份数字时,强烈建议使用以下枚举值,以避免混淆。

常量说明
Calendar.January一月 (0)
Calendar.February二月 (1)
Calendar.March三月 (2)
Calendar.April四月 (3)
Calendar.May五月 (4)
Calendar.June六月 (5)
Calendar.July七月 (6)
Calendar.August八月 (7)
Calendar.September九月 (8)
Calendar.October十月 (9)
Calendar.November十一月 (10)
Calendar.December十二月 (11)

另请参见 MonthGridCalendar

属性文档

from : date

该属性表示开始日期。


to : date

该属性用于保存结束日期。


方法文档

int indexOf(Date date)

返回指定date 的模型索引。


int indexOf(int year, int month)

返回指定yearmonth 的模型索引。


int monthAt(int index)

Returns the month number at the specified modelindex.


int yearAt(int index)

返回指定型号的年号index


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.