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)
That's a lot of questions packed into one question. I'll focus on your stated intentions:
If you have a binding, like so:
And you later change the value of
x, under the hood it should be emitting anxChangedsignal. The binding meansywill be listening for that signal and update accordingly.Now if you later change
y, like so:The binding is broken.
ywill no longer listen for changes fromx.For animations, if you tell
yto animate to a value different fromx, then the binding is broken. Intermediate animation steps do not break the binding though. You can haveystill bound tox, but asxchanges,ycan animate those changes and remain bound.