Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
Qt for MCUs 2.3.1
-
None
-
-
a93561ee33573940ce26f00fc917a0b027740403, 03237697fca6a096defc6b636e668a03d3889f17, 9d1c44f7d65ef2dc10ff5fb72c52a35fe8e49f11 (2.5.1)
Description
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" } }