-
Bug
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
Qt for MCUs 2.3.1
-
None
The original snippet uses AnchorChanges for changing margins, which the page itself says not possible. In fact, it doesn't work when pasted to the Qt Creator and run.
link : https://doc.qt.io/QtForMCUs-2.4/qml-qtquick-anchorchanges.html#details
<original>
import QtQuick 2.15 Rectangle { id: window width: 120; height: 120 color: "black" Rectangle { id: anchorRectStart; x: 60; y: 60; height: 60; width: 60; color: "yellow"} Rectangle { id: anchorRectEnd; x: 0; y: 0; height: 60; width: 60; color: "blue"} Rectangle { id: myRect; color: "red" anchors { top: anchorRectStart.top bottom: anchorRectStart.bottom left: anchorRectStart.left right: anchorRectStart.right topMargin: 10 bottomMargin: 10 leftMargin: 10 rightMargin: 10 } } states: State { name: "reanchored" AnchorChanges { target: myRect anchors { top: anchorRectEnd.top bottom: anchorRectEnd.bottom left: anchorRectEnd.left right: anchorRectEnd.right topMargin: 20 bottomMargin: 20 leftMargin: 20 rightMargin: 20 } } } MouseArea { anchors.fill: parent; onClicked: window.state = "reanchored" } }
The code should be like this. This code worked as intended.
import QtQuick 2.15 Rectangle { id: window width: 120; height: 120 color: "black" Rectangle { id: anchorRectStart; x: 60; y: 60; height: 60; width: 60; color: "yellow"} Rectangle { id: anchorRectEnd; x: 0; y: 0; height: 60; width: 60; color: "blue"} Rectangle { id: myRect; color: "red" anchors { top: anchorRectStart.top bottom: anchorRectStart.bottom left: anchorRectStart.left right: anchorRectStart.right topMargin: 10 bottomMargin: 10 leftMargin: 10 rightMargin: 10 } } states: State { name: "reanchored" AnchorChanges { target: myRect anchors { top: anchorRectEnd.top bottom: anchorRectEnd.bottom left: anchorRectEnd.left right: anchorRectEnd.right } } PropertyChanges { target: myRect anchors { topMargin: 20 bottomMargin: 20 leftMargin: 20 rightMargin: 20 } } } MouseArea { anchors.fill: parent; onClicked: window.state = "reanchored" } }