No stretch settings in QML Layouts?
-
Hi,
I'm trying to move my desktop projects/products from QWidgets to QML and I keep hitting the stretch problem in QML Layouts; specifically, there aren't any stretch settings.
Row, column and grid layouts in QWidgets have stretch properties, which are really useful for expanding specific columns or rows, and not others. E.g. for a row layout with 4 cells, "0,1, 2, 0"
Is there anything like this in QML? I've read other posts with similar questions but I don't see any workable answers.
QML's "Layout.fillWidth: true" and "Layout.fillHeight: true" doesn't quite work for this.
- Using them in more than one cell results in both cells expanding equally, and there is no way to set stretch proportions (like different non-zero values in the QWidgets layouts).
- Using them inside a child layout within a cell (e.g. in a RowLayout that is inside a GridLayout cell) - to force the contents to use the whole cell height or width - often translates higher, to the parent layout and results in the parent cell expanding within its whole layout.
All in all, I haven't found any way for QML layouts to behave like, and as well as, QWidgets layouts.
Any help with this is most appreciated.
Also regarding point 2, I've found that to fill all of a cell when nesting layouts, I have to use a Rectangle between the two layouts, to make the child layout fully use the space of the parent layout cell. E.g. RowLayout inside a transparent Rectangle inside a GridLayout cell. This way, in the RowLayout, I can set "anchors.fill: parent" to get the Row to use all of the Rectangle.
And please don't suggest using lots of anchors. The Qt documentation suggests either going for layouts or going for anchors, and not mixing both. It also suggests layouts are for resizable desktop apps - which mine are.
Thx,
Michael -
Hi,
I'm trying to move my desktop projects/products from QWidgets to QML and I keep hitting the stretch problem in QML Layouts; specifically, there aren't any stretch settings.
Row, column and grid layouts in QWidgets have stretch properties, which are really useful for expanding specific columns or rows, and not others. E.g. for a row layout with 4 cells, "0,1, 2, 0"
Is there anything like this in QML? I've read other posts with similar questions but I don't see any workable answers.
QML's "Layout.fillWidth: true" and "Layout.fillHeight: true" doesn't quite work for this.
- Using them in more than one cell results in both cells expanding equally, and there is no way to set stretch proportions (like different non-zero values in the QWidgets layouts).
- Using them inside a child layout within a cell (e.g. in a RowLayout that is inside a GridLayout cell) - to force the contents to use the whole cell height or width - often translates higher, to the parent layout and results in the parent cell expanding within its whole layout.
All in all, I haven't found any way for QML layouts to behave like, and as well as, QWidgets layouts.
Any help with this is most appreciated.
Also regarding point 2, I've found that to fill all of a cell when nesting layouts, I have to use a Rectangle between the two layouts, to make the child layout fully use the space of the parent layout cell. E.g. RowLayout inside a transparent Rectangle inside a GridLayout cell. This way, in the RowLayout, I can set "anchors.fill: parent" to get the Row to use all of the Rectangle.
And please don't suggest using lots of anchors. The Qt documentation suggests either going for layouts or going for anchors, and not mixing both. It also suggests layouts are for resizable desktop apps - which mine are.
Thx,
MichaelHere's a specific example of how QML Layouts appears to be broken.
I have a GridLayout with 4 colums and 5 rows. The cells in the 3th column each contain a GroupBox and with "Layout.fillWidth: true" in each GroupBox, the 3rd column expands when the app width is increased. That's what I want.
However in the top cell of the 4th column, I want to have text which is right and top aligned within the cell. QML won't let me do it. I've tried various alignments and anchors, tried putting the text in a Rectangle & child GridLayout within the parent cell and with addition Rectangles (inside the child GridLayout) to push the text to the top right corner, and even tried used "Layout.fillWidth: true" in the Rectangle. Nothing works, and "Layout.fillWidth: true" causes the 4th column to expand at the same rate as the 3rd column, which is not what I want.
Am I missing something obvious?
Thanks,
Michael