2

My question relates to Calendar but could be applied to every QML visual Item. Is there any way to repaint an Item manually?

In my case I have a Calendar with custom content(small orange digit in the cell 26):

enter image description here

To do that I use styles:

import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

Window {
    width: 300
    height: 300
    id: window
    Calendar {
        id: calendar
        anchors.fill: parent
        property var dataArr: {26: 7}
        style: CalendarStyle {
            dayDelegate: Rectangle {
                Label {
                    text: styleData.date.getDate()
                    anchors.centerIn: parent
                }
                Label {
                    font.pixelSize: 8
                    anchors.right: parent.right
                    anchors.bottom: parent.bottom
                    width: 12
                    height: 10
                    horizontalAlignment: Text.AlignHCenter
                    text: calendar.dataArr[styleData.date.getDate()] ? calendar.dataArr[styleData.date.getDate()] : ""
                    color: "orange"
                }
            }
        }
        Component.onCompleted: {
            calendar.dataArr[26] = 8; //that doesn't work
        }
    }
}

That works fine with static array, but if I change a value in the data array it doesn't update a cell. How can I force the Calendar to update?

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
folibis
  • 12,048
  • 6
  • 54
  • 97

1 Answers1

2

As per this the updates for bindings won't be triggered for var in this way. They have provided the solution after the example. Applying it here:

property var dataArr: new Object( {26: 7} )
...
Component.onCompleted: {
   dataArr = new Object( {26: 8} )
}
BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
astre
  • 798
  • 6
  • 14
  • yes, thanks @astre, it looks that this is the only way to repaint an item. I think it will be nice to have some function to update an item manually. I'll create a ticket in Qt bug tracker – folibis Oct 26 '15 at 22:37