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).
-
Thanks for suggestion. This way elements are positioned correctly, but the green rectangle is covered by other elements of
ColumnLayout. I want it to be on top of every element ofColumnLayout. -
Never mind, I had to set z property of the item, not the rectangle. It seems obvious now.
Thank you -
M michal.19937 has marked this topic as solved