Positioning advice
-
Hi there, could anyone please help me understand how to create a certain positioning? I don't care whether I use Columns/Rows or ColumnLayout/RowLayout but I am basically making a ListView delegate. It needs to have a Rectangle for the background, a colored image 10px by the height of the rectangle on the left, with two rows to the right and filling the width. There should be a margin on top and left of the text and to the right and bottom of the images. In the bottom row I need two objects justified to the right. I have tried this in various ways, but the closest I can get is with everything in the right place but the images at the left of the row. All attempts to justify the images to the right seem to fail.
Things I have tried:
Make bottom row a RowLayout with an item before the images that fills width
Make parent layout a ColumnLayout and bottom row a RowLayout with Layout.alignment: Qt.AlignRight
Make bottom row a regular Row and with first image anchor.right: parent.right and second image anchor.right: img1.left
I have tried Layout.fillWidth: true and false in the bottom row
I have tried every combination of Row/RowLayout/Column/ColumnLayout
Right alignments/anchors in the imagesNone of this works. Please help! This is Qt5.15.2
Below is a text map of what I would like and the code that gets me the closest I can get.
+----+---------------------------------+ |Rect| Row 1 Text | | +---------------------------------+ | | |Img1|Img2| +----+---------------------------------+Component { id: teamsListD Rectangle { color: "#000000" height: teamRL.height width: parent.width RowLayout { id: teamRL anchors.left: parent.left width: parent.width Rectangle { width: 10 height: teamCL.height+40 } ColumnLayout { Layout.fillWidth: true id: teamCL spacing: 20 Text { Layout.leftMargin: 10 text: "Team 1" color: "#FFFFFF" } RowLayout { spacing: 10 Layout.alignment: Qt.AlignRight Image { id: trashI source: "../../images/svg_images/garbage2.svg" height: 20 width: 20 fillMode: Qt.KeepAspectRatio } Image { id: editI source: "../../images/svg_images/edit2.svg" height: 20 width: 20 fillMode: Qt.KeepAspectRatio } } } } } } -
Ok let me reply to my own post.
I have found that this kind of works if I wrap the bottom row in an Item with Layout.fillWidth: true, set the height to the row height, and then anchor the row to the right of the item. Is the dummy Item the only way to do this?
Component { id: teamsListD Rectangle { color: "#000000" height: teamRL.height width: parent.width RowLayout { id: teamRL anchors.left: parent.left width: parent.width Rectangle { width: 10 height: teamCL.height } ColumnLayout { id: teamCL spacing: 20 Layout.fillWidth: true Layout.bottomMargin: 10 Text { Layout.leftMargin: 10 Layout.topMargin: 10 text: "Team 1" color: "#FFFFFF" } Item { height: botRow.height Layout.fillWidth: true Layout.rightMargin: 10 Row { id:botRow spacing: 10 anchors.right: parent.right Image { id: trashI source: "../../images/svg_images/garbage2.svg" height: 20 width: 20 fillMode: Qt.KeepAspectRatio } Image { id: editI source: "../../images/svg_images/edit2.svg" height: 20 width: 20 fillMode: Qt.KeepAspectRatio } } } } } } }