I am trying to understand the inner workings of QtQuick/Calendar example. can be found here:
https://qt-project.org/doc/qt-5/qtquickcontrols-calendar-example.html
and the actual code is in:
https://qt-project.org/doc/qt-5/qtquickcontrols-calendar-qml-main-qml.html
In its dayDelegate it has Rectangle that is defined like this:
dayDelegate: Item {
Rectangle {
anchors.fill: parent
border.color: "transparent"
color: styleData.date !== undefined && styleData.selected ? selectedDateColor : "transparent"
anchors.margins: styleData.selected ? -1 : 0
}
I am trying to add an ability to do custom processing depending on where inside the delegate user clicks. I change the delegate to look like:
dayDelegate: Item {
Rectangle {
anchors.fill: parent
border.color: "transparent"
color: styleData.date !== undefined && styleData.selected ? selectedDateColor : "transparent"
anchors.margins: styleData.selected ? -1 : 0
MouseArea {
anchors.fill: parent
onClicked:
{
dayDelegateText.text = dayDelegateText.text == "two" ? "one" : "two"
}
}
But once I do this, Calendar no longer reacts to clicks outside of currently selected item. What am I breaking by adding this MouseArea?
Even more confusing is that if I add this area inside a rectangle that is a child of delegate's rectangle and invisibly overlaps it everything works as I wanted it to and I can both operate inside a delegate and change selection.
dayDelegate: Item {
Rectangle {
anchors.fill: parent
border.color: "transparent"
color: styleData.date !== undefined && styleData.selected ? selectedDateColor : "transparent"
anchors.margins: styleData.selected ? -1 : 0
Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
width: styleData.selected ? parent.width/2 : 0
height:styleData.selected ? parent.height/2 : 0
color: "gray"
MouseArea {
anchors.fill: parent
onClicked:
{
dayDelegateText.text = dayDelegateText.text == "two" ? "one" : "two"
}
}
}
}