我的问题与日历
有关,但可以应用于每个QML视觉Item
。有没有办法手动重新绘制Item
?
就我而言,我有一个带有自定义内容的日历
(单元格 26 中的橙色小数字):
为此,我使用样式:
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
}
}
}
这适用于静态数组,但如果我更改数据数组中的值,它不会更新单元格。如何强制日历
更新?
最佳答案
根据 this通过这种方式,var
不会触发绑定(bind)的更新。他们在示例之后提供了解决方案。在这里应用它:
property var dataArr: new Object( {26: 7} )
...
Component.onCompleted: {
dataArr = new Object( {26: 8} )
}
关于qml - 手动更新/重新绘制项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33337942/