Let's say property 'x' has an immidiate value in QML,
and another property 'y' is bound to 'x'
Text { id: mytext; x: 100; y: x; text: x+","+y; }
Is it legal to assign another value to any of the properties?
i.e. is binding 'y: x' simply deleted/overriden, or it enters some sort of unsupported/erroneous state?
Button { onClicked: { mytext.x = 120; mytext.y = 130; } }
What if I specify another binding explicitly in the same QML file:
Binding { target: mytext; property: "x"; value: 140; }
Binding on y { value: 150; } //insert this line into mytext
Is it different if "when" is specified? Can I specify multiple conditional bindings?
Binding { target: mytext; property: "x"; value: 160; when: width < 600; }
Binding { target: mytext; property: "x"; value: 170; when: width > 800; }
Is Animation or Behavior any different?
NumberAnimation on x { from: 100; to: 200; duration: 500 } //insert line into mytext
NumberAnimation { target: mytext; property: "y"; from: 100; to: 200; duration: 500 }
Is assigning (or creating a binding) from C++ code any different?
mytextPointer->setX(190);
Please note that I'm not asking if this works on your system - instead I'd like to know if this code supposed to work as intended.
My intention is:
- "directly specified" values (x=100 and y=x) are default,
- whenever they are assigned, their value is replaced with whatever was assigned
My current undestanding of documentation is:
- having multiple conditional bindings is ok (as long as both conditions cannot be true at the same time?) - the binding restores previous value (not necessarily default) after condition is no longer true;
- animation/behavior/transition overrides the binding when it is running/active, but does not restore previous value(?) after finishing;
- everything else is unclear (but apparently works; and if multiple bindings are assigned then evidently the first one provides the value)
question from:
https://stackoverflow.com/questions/65832560/is-it-legal-to-assign-to-property-that-already-has-binding-defined-in-qml 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…