I am adding Image
objects dynamically to a GridLayout
in a QML
file in qt
. I want to position the image items so that each new image item comes to the right side of the previous one and if there is no place in that row, it is placed directly to the next row. It is exactly the way how I typed this question, i.e. letters are my image items and text box is the layout.
However the output is following:
The layout leaves space between items as seen in the screenshot. I've read through the properties of gridlayout and tried many combinations out but didn't come up with the right combination. These are the properties I set so far:
GridLayout {
id: myLayout
anchors.fill: parent
columnSpacing: preferredColumnSpacing
rowSpacing: preferredRowSpacing
Component {
id: myImageComponent
Image {
visible: true
Layout.alignment: (Qt.AlignLeft | Qt.AlignTop)
Layout.preferredWidth: preferredImageWidth
Layout.preferredHeight: preferredImageHeight
}
}
}
Which modification gives me the expected behaviour?
Edit: in the screenshot above, the layout has 9 columns, 4 rows but 17 image items.