Hi!
My situation:
Trying to code a calendar with QML, so I am using Repeater { ... } that will display days in selected month. As a model for Repeater I'm using a list with instances of class, that represent data for every day:
context
->setContextProperty
("_days_list",
QVariant::fromValue(daysList
));
context->setContextProperty("_days_list", QVariant::fromValue(daysList));
To copy to clipboard, switch view to plain text mode
For simplicity in class that represents data for days I have properties:
Q_PROPERTY( int dayNum READ getDayNum WRITE setDayNum NOTIFY dayNumChanged)
Q_PROPERTY( QQmlListProperty<CalEvent> getDayEvents READ getDayEvents CONSTANT)
Q_PROPERTY( int dayNum READ getDayNum WRITE setDayNum NOTIFY dayNumChanged)
Q_PROPERTY( QQmlListProperty<CalEvent> getDayEvents READ getDayEvents CONSTANT)
To copy to clipboard, switch view to plain text mode
I have no problem displaying "dayNum"
Repeater {
model: _days_list
Rectangle {
id: dayRectangle
width: 25
height: 25
Text {
id: daysText
text: model.modelData.dayNum
anchors.centerIn: parent
}
}
}
Repeater {
model: _days_list
Rectangle {
id: dayRectangle
width: 25
height: 25
Text {
id: daysText
text: model.modelData.dayNum
anchors.centerIn: parent
}
}
}
To copy to clipboard, switch view to plain text mode
But there is my problem: how can I access QQmlListProperty<CalEvent> with events for each day? For example after double click on Rectangle that represents one tile in calendar's grid I want to open a Window, that will show names of all day's events.
If i do this:
onDoubleClicked: {
var component = Qt.createComponent("eventDialog.qml");
eventWin = component.createObject(mainWindow);
console.log(model.modelData.getDayEvents)
eventWin.show();
}
onDoubleClicked: {
var component = Qt.createComponent("eventDialog.qml");
eventWin = component.createObject(mainWindow);
console.log(model.modelData.getDayEvents)
eventWin.show();
}
To copy to clipboard, switch view to plain text mode
I get output into console: "qml: [object Object]", but don't know how to access e.g first event of the day.
In advance: thanks for help.
P.S: my source codes for calendar are on github: here
Bookmarks