CalendarModel QML Type

A calendar model. More...

Import Statement: import Qt.labs.calendar 1.0

Properties

Methods

Detailed Description

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 { }
}

In addition to the index property, a list of model data roles are available in the context of each delegate:

model.month : intThe number of the month
model.year : intThe number of the year

The Qt Labs Calendar module uses 0-based month numbers to be consistent with the JavaScript Date type, that is used by the QML language. This means that Date::getMonth() can be passed to the methods as is. When dealing with month numbers directly, it is highly recommended to use the following enumeration values to avoid confusion.

ConstantDescription
Calendar.JanuaryJanuary (0)
Calendar.FebruaryFebruary (1)
Calendar.MarchMarch (2)
Calendar.AprilApril (3)
Calendar.MayMay (4)
Calendar.JuneJune (5)
Calendar.JulyJuly (6)
Calendar.AugustAugust (7)
Calendar.SeptemberSeptember (8)
Calendar.OctoberOctober (9)
Calendar.NovemberNovember (10)
Calendar.DecemberDecember (11)

Note: Types in Qt.labs modules are not guaranteed to remain compatible in future versions.

See also MonthGrid and Calendar.

Property Documentation

from : date

This property holds the start date.


to : date

This property holds the end date.


Method Documentation

int indexOf(int year, int month)

Returns the model index of the specified year and month.


int indexOf(Date date)

Returns the model index of the specified date.


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.


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