Reducing bindings fail
Solved
QML and Qt Quick
-
I am trying to reduce the amount of property bindings on this small bit of code used as an example but I am running into a problem. For some reason, the text is not showing. Here is the code:
import QtQuick 2.12 import QtQuick.Controls 2.5 import QtQuick.Window 2.0 ApplicationWindow { id: root visible: true width: 640 height: 480 // Rectangle // { // id: content // anchors.centerIn: parent // width: theText.width + 10 // height: theText.height + 10 // color: mouseArea.pressed ? "green" : "blue" // Text // { // id: theText // anchors.centerIn: parent // text: mouseArea.pressed ? "Technologies" : "Jet" // } // MouseArea // { // id: mouseArea // anchors.fill: parent // } // } Rectangle { id: content anchors.centerIn: parent width: theText.width + 10 height: theText.height + 10 Text { id: theText anchors.centerIn: parent } MouseArea { id: mouseArea anchors.fill: parent onPressedChanged: { if (pressed) { content.color = "blue"; theText.text = "Jet"; } else { content.color = "green"; theText.text = "Technologies"; } } } } }
note that in the commented version everything works as expected. However, when I run the uncommented version the text doesn't show up unless I assign a value to
theText
'stext
property directly, why is that? -
For my curiosity , why do you want to do that?
-