本页内容

WeekNumberColumn QML Type

一周序号列。更多...

Import Statement: import QtQuick.Controls
Inherits:

Control

属性

详细说明

WeekNumberColumn 在一列中显示周数。这些周数是根据给定的month 和year ,并使用指定的locale 计算得出的。

显示周数的“周数”列

WeekNumberColumn {
    month: Calendar.December
    year: 2015
    locale: Qt.locale("en_US")
}

WeekNumberColumn 可以作为独立控件使用,但通常与MonthGrid 配合使用。无论使用场景如何,列的位置均由用户自行决定。

日历布局中的“第几周”列

RowLayout {
    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.fillHeight: true
    }
}

通过实现custom delegate ,可以更改 WeekNumberColumn 的视觉外观。

另请参阅 MonthGrid 和DayOfWeekRow 。

属性文档

delegate : Component

该属性存储用于可视化每个周数的项委托。

除了index 属性外,每个委托的上下文中还提供了一系列模型数据角色:

model.weekNumber: int周数

以下代码片段展示了项目委托的默认实现。可将其作为实现自定义委托的起点。

delegate: Text {
    text: weekNumber
    font: control.font
    horizontalAlignment: Text.AlignHCenter
    verticalAlignment: Text.AlignVCenter

    required property int weekNumber
}

WeekNumberColumn 不会获取该委托的所有权。

month : int

该属性存储用于计算周号的月份编号。默认值为当前月份。

日历相关类型在 Qt Quick Controls 采用以0为起点的月份编号,与JavaScript的Date对象类似。但这与QDate 不同,后者中的月份编号是从1开始的。

为避免混淆,您可以使用以下枚举值:

常量描述
Calendar.January一月 (0)
Calendar.February二月 (1)
Calendar.March3月 (2)
Calendar.April4月 (3)
Calendar.May5月 (4)
Calendar.June6月 (5)
Calendar.July7月 (6)
Calendar.August8月 (7)
Calendar.September9月 (8)
Calendar.October10月 (9)
Calendar.November11月 (10)
Calendar.December12月 (11)

另请参阅 Calendar 。

year : int

该属性用于指定计算周数所依据的年份编号。

该值必须在-271820 到275759 之间。默认值为当前年份。

© 2026 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.