QML Property Binding update does not propagate
-
Hi,
I have a QML property size, which I am trying to use to change many of my attributes to half size when I reach a split screen state. However, when I update the size property in this state, the reduction in size does not propogate to things such as font size which depend upon it.
@
Item{
id:navTab
property bool split: data.splitScreen
property double size: 1
Rectangle {
width: 100navTab.size
height: 100navTab.size
color: "black"
border.color: "lawngreen"
border.width: 5navTab.size
Text{
anchors.centerIn: parent
text: "Info"
font.pointSize: 18navTab.size
color: "white"
}
radius: 10*navTab.size
}
states: [
State{
name: "split"; when: split
PropertyChanges {
target: navTab
size: 1/2
}
}
]
}
@
What am I missing about bindings here, which will allow me to do this?I have also tried simplifying this and using a fontsize property, but even this alone does not propagate when updated.
@
Text {
text: "HEADING"
font.pointSize: navTab.fontsize
color: "white"
}
State{
name: "split"; when: carData.splitScreen
PropertyChanges {
target: navTab
fontsize: 9
}
}
@Also, trying to create a dependency on a f--unction doesn't seem to work either
@
function getFontSize(){
return navTab.fontsize;
}
Text{
text: "Info"
font.pointSize: navTab.getFontSize()
}
@ -
You may need to give more information (which platform are you on, etc).
The following code demonstrates that both bindings to properties directly, and bindings which involve calls to functions which themselves access proeprties, both cause changes to be propagated:
@
import QtQuick 2.0Item {
id: root
width: 600
height: 600property double size: 50 function getSize() { return root.size; } Rectangle { id: blueRect anchors.left: parent.left width: root.size * 2 height: root.size * 4 color: "blue" } Rectangle { id: redRect anchors.right: parent.right width: root.getSize() * 2 height: root.getSize() * 4 color: "red" } Timer { interval: 1000 repeat: true running: true onTriggered: if (root.size == 50) root.size = 100; else root.size = 50; }
}
@ -
I made minimal changes to your example to make it self-contained:
@
import QtQuick 1.1Item {
id:navTab
property bool split: width < 300
property double size: 1
Rectangle {
width: 100navTab.size
height: 100navTab.size
color: "black"
border.color: "lawngreen"
border.width: 5*navTab.size
Text{
anchors.centerIn: parent
text: "Info"font.pointSize: 18*navTab.size color: "white" } radius: 10*navTab.size } states: [ State{ name: "split"; when: split PropertyChanges { target: navTab size: 1/2 } } ]
}
@All bindings are evaluated for me as expected. So either
- you're using another Qt version with a bug
- your logic in data.splitScreen is faulty, or
- your example doesn't really show the deficiency that you've been talking about :)
-
Hi,
Thank you both for your kind help, I appreciate the time you took to examine my problem. You were correct in that the problem was with data.splitScreen. I had assumed it was working, since I was getting split screens, but I was actually creating the splitScreens within my main QML with a property, which I had not reset to depend on data.SplitScreen when I modified it. Thanks again for your help.