Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
6.4.2
-
None
Description
Anchors are pretty neat and they are quite flexible.
One thing that is pretty awesome is that you can actively assign 'undefined' which makes them more powerful.
For instance you can change the top anchor to undefined and set the verticalCenter instead at some button press.
Where this falls down, though, is in a declarative setting.
Take the attached example QML application (tested with 'qml6' executable).
We have a property that changes value and the two anchors on an object:
anchors.top: cb.checked ? undefined: parent.top
anchors.bottom: cb.checked ? parent.verticalCenter : undefined
What I expect to happen is, in detail, that the object this is set on will update those top and bottom properties by calling the C++ setters.
Then at the end of the cb checked changed signal (or simply in a new event in the eventloop) figure out the new geometry and positioning based on the changed anchors.
What is actually happening (I'm guessing, didn't look at the code), is that the top and bottom properties are set individually one after the other. And they protect against internal state inconsistencies and thus they reject some changes or make adjustments to height instead.
The result is very non-intuitive and basically means you can't use constructions like the above if you actually expect the property to be changed during the lifetime of the object you are anchoring.
It would likely work if you use this in a procedural manner. A 'onCheckedChange' that first sets the one to undefined and then the other to the new value.
Please consider re-architecting the anchors stuff to make it possible to use them more declaratively.