How to get x, y from an element of ColumnLayout?
-
Hello,
Consider the code:import QtQuick import QtQuick.Layouts Window { width: 640 height: 480 visible: true title: qsTr("Hello World") ColumnLayout { anchors.fill: parent Rectangle { id: re width: 200 height: 100 color: "red" } } Rectangle { x: mapFromItem(re, 0, 0).x y: mapFromItem(re, 0, 0).y z: 1 width: 100 height: 50 color: "green" } }I'm trying to position the green rectangle on top of the red one, however it always lands in the top left corner of the window. If I replace
ColumnLayoutwithRectangle, the code works as intended, soColumnLayoutmust be the problem.
How do I get correct x and y of the red rectangle? -
Hello,
Consider the code:import QtQuick import QtQuick.Layouts Window { width: 640 height: 480 visible: true title: qsTr("Hello World") ColumnLayout { anchors.fill: parent Rectangle { id: re width: 200 height: 100 color: "red" } } Rectangle { x: mapFromItem(re, 0, 0).x y: mapFromItem(re, 0, 0).y z: 1 width: 100 height: 50 color: "green" } }I'm trying to position the green rectangle on top of the red one, however it always lands in the top left corner of the window. If I replace
ColumnLayoutwithRectangle, the code works as intended, soColumnLayoutmust be the problem.
How do I get correct x and y of the red rectangle?@michal.19937 Put an item in the layout. In that item you put the red rectangle and then the green one at the same coordinates (whatever the reason you want to do this).