Standard qml Property binding is not read properly.
-
I have a bool property which is updated based on another property as shown below code
import QtQuick 2.6 import QtQuick.Window 2.2 Window { id: main1 visible: true width: 1024 height: 720 title: qsTr("Hello World") property bool validator: rect1.color !== "red" ? false : true Row { id: root width: parent.width height: parent.height Repeater { id:rp1 model: 10 Rectangle { id:rect1 visible: true color: "red" height: 50 width: 50 MouseArea { anchors.fill: parent onClicked: rect1.color = "green" } } } } Rectangle { id: rect2 anchors.bottom: parent.bottom color: "Yellow" width: 100 height: 75 visible: !validator } }
The above code is just a sample. Here property "validator" is not updating whenever rectangle inside Repeater is clicked. However the color of rectangle is changing individually to green. But if the property change was caught by qml, then the rect2 should be invisible. Curious why internal qml property is not recognizing this change. Request to help
Thanks in advance.
-
I have a bool property which is updated based on another property as shown below code
import QtQuick 2.6 import QtQuick.Window 2.2 Window { id: main1 visible: true width: 1024 height: 720 title: qsTr("Hello World") property bool validator: rect1.color !== "red" ? false : true Row { id: root width: parent.width height: parent.height Repeater { id:rp1 model: 10 Rectangle { id:rect1 visible: true color: "red" height: 50 width: 50 MouseArea { anchors.fill: parent onClicked: rect1.color = "green" } } } } Rectangle { id: rect2 anchors.bottom: parent.bottom color: "Yellow" width: 100 height: 75 visible: !validator } }
The above code is just a sample. Here property "validator" is not updating whenever rectangle inside Repeater is clicked. However the color of rectangle is changing individually to green. But if the property change was caught by qml, then the rect2 should be invisible. Curious why internal qml property is not recognizing this change. Request to help
Thanks in advance.
@Nitheesh said in Standard qml Property binding is not read properly.:
rect1.color !== "red"
is true whenever the color is not the string "red", which is always the case.
You should use Qt.colorEqual() instead for the check -
@Nitheesh said in Standard qml Property binding is not read properly.:
rect1.color !== "red"
is true whenever the color is not the string "red", which is always the case.
You should use Qt.colorEqual() instead for the check@raven-worx Thanks for the reply! As per you changed the code to Qt.colorEqual() check. Still Property is not caught properly. Let me put it in this way, instead of color will change the height of the rectangle and corresponding bool check shall be assigned to variable validator as in code below:
import QtQuick 2.6 import QtQuick.Window 2.2 Window { id: main1 visible: true width: 1024 height: 720 title: qsTr("Hello World") property bool validator: rect1.height === 50 ? false : true Row { id: root width: parent.width height: parent.height Repeater { id:rp1 model: 10 Rectangle { id:rect1 visible: true color: "red" height: 50 width: 50 MouseArea { anchors.fill: parent onClicked: rect1.height = 200 } } } } Rectangle { id: rect2 anchors.bottom: parent.bottom color: "Yellow" width: 100 height: 75 visible: !validator } }
Even in this case the rect2 is not invisible upon click of rect1 except only height of rect1 changes.
-
@raven-worx Thanks for the reply! As per you changed the code to Qt.colorEqual() check. Still Property is not caught properly. Let me put it in this way, instead of color will change the height of the rectangle and corresponding bool check shall be assigned to variable validator as in code below:
import QtQuick 2.6 import QtQuick.Window 2.2 Window { id: main1 visible: true width: 1024 height: 720 title: qsTr("Hello World") property bool validator: rect1.height === 50 ? false : true Row { id: root width: parent.width height: parent.height Repeater { id:rp1 model: 10 Rectangle { id:rect1 visible: true color: "red" height: 50 width: 50 MouseArea { anchors.fill: parent onClicked: rect1.height = 200 } } } } Rectangle { id: rect2 anchors.bottom: parent.bottom color: "Yellow" width: 100 height: 75 visible: !validator } }
Even in this case the rect2 is not invisible upon click of rect1 except only height of rect1 changes.
@Nitheesh said in Standard qml Property binding is not read properly.:
rect1.height === 50
same problem again.
You first need to understand that===
is only true if the value AND the type matches. Now you are comparing real to int.
So either use==
only orrect1.height === 50.0
-
I have a bool property which is updated based on another property as shown below code
import QtQuick 2.6 import QtQuick.Window 2.2 Window { id: main1 visible: true width: 1024 height: 720 title: qsTr("Hello World") property bool validator: rect1.color !== "red" ? false : true Row { id: root width: parent.width height: parent.height Repeater { id:rp1 model: 10 Rectangle { id:rect1 visible: true color: "red" height: 50 width: 50 MouseArea { anchors.fill: parent onClicked: rect1.color = "green" } } } } Rectangle { id: rect2 anchors.bottom: parent.bottom color: "Yellow" width: 100 height: 75 visible: !validator } }
The above code is just a sample. Here property "validator" is not updating whenever rectangle inside Repeater is clicked. However the color of rectangle is changing individually to green. But if the property change was caught by qml, then the rect2 should be invisible. Curious why internal qml property is not recognizing this change. Request to help
Thanks in advance.
@Nitheesh Repeater takes a delegate and creates objects according to model.
Therefore rect1 is not an object, it is a component. Repeater creates 10 Rectangle object, and which one's color will be binded to validator? It does not make sense.
You should change your design so that it will catch results from signals. For example you can define a single in repeater, and emit it from its children (ie. rectangles) then catch elsewhere.
-
@Nitheesh Repeater takes a delegate and creates objects according to model.
Therefore rect1 is not an object, it is a component. Repeater creates 10 Rectangle object, and which one's color will be binded to validator? It does not make sense.
You should change your design so that it will catch results from signals. For example you can define a single in repeater, and emit it from its children (ie. rectangles) then catch elsewhere.