MonthGrid QML Type
日历月的天数网格。更多
Import Statement: | import QtQuick.Controls |
Inherits: |
属性
信号
- clicked(date date)
- pressAndHold(date date)
- pressed(date date)
- released(date date)
详细说明
MonthGrid 以网格形式显示日历月份。其内容是根据给定的month 和year 计算得出的,并使用指定的locale 。
MonthGrid { month: Calendar.December year: 2015 locale: Qt.locale("en_US") }
MonthGrid 可作为独立控件使用,但最常用的是与DayOfWeekRow 和WeekNumberColumn 结合使用。无论使用何种情况,网格的定位都由用户自行决定。
GridLayout { columns: 2 DayOfWeekRow { locale: grid.locale Layout.column: 1 Layout.fillWidth: true } WeekNumberColumn { month: grid.month year: grid.year locale: grid.locale Layout.fillHeight: true } MonthGrid { id: grid month: Calendar.December year: 2015 locale: Qt.locale("en_US") Layout.fillWidth: true Layout.fillHeight: true } }
可以通过实施custom delegate 来改变 MonthGrid 的视觉外观。
查看任何给定月份时,MonthGrid 都会显示上个月和下个月的天数。这意味着它始终显示六行,即使第一行或最后一行完全在相邻月份内。
本地化日期
要本地化日期,请使用Locale.toString()。例如,在阿拉伯语地区显示星期数字:
MonthGrid { id: monthGrid month: Calendar.December year: 2015 locale: Qt.locale("ar") delegate: Text { horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter opacity: model.month === monthGrid.month ? 1 : 0 text: monthGrid.locale.toString(model.date, "d") font: monthGrid.font required property var model } }
另请参阅 DayOfWeekRow,WeekNumberColumn, 和CalendarModel 。
属性文档
delegate : Component |
该属性包含可视化每天的项目委托。
除了index
属性外,在每个委托的上下文中还有一个模型数据角色列表:
model.date : 日期 | 单元格的日期 |
model.day: int | 当天的数字 |
model.today: bool | 委托是否代表今天 |
model.weekNumber: int | 星期数 |
model.month: int | 月份编号 |
model.year: int | 年的编号 |
以下代码段介绍了 item 委托的默认实现。它可以作为实现自定义委托的起点。
delegate: Text { horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter opacity: model.month === control.month ? 1 : 0 text: model.day font: control.font required property var model }
month : 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) |
另请参见 Calendar 。
year : int |
该属性包含年号。
-271820
275759
默认值为当前年份。
信号文档
clicked(date date) |
点击date 时会发出该信号。
注: 相应的处理程序是onClicked
。
pressAndHold(date date) |
按住date 时发出此信号。
注: 相应的处理程序是onPressAndHold
。
pressed(date date) |
按下date 时会发出该信号。
注: 相应的处理程序是onPressed
。
released(date date) |
释放date 时发出此信号。
注: 相应的处理程序是onReleased
。
© 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.