Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.9
-
None
Description
As the official document says, there are two attached properties since Qt 6.5, Layout.verticalStretchFactor and Layout.horizontalStretchFactor, which allow you to specify the vertical and horizontal stretch factor. For example, if the first item has a stretch factor of 1 and the second item has a stretch factor of 2, the first item will aim to get 1/3 of the available space, and the second will aim to get 2/3 of the available space.
However, I had a try and did not get the expected result. The two items had the same size.
Examples:
https://forum.qt.io/post/809232
https://forum.qt.io/post/825427
https://stackoverflow.com/q/78968268/630169
https://stackoverflow.com/a/78972814/630169
solved by adding preferredWidth like this:
RowLayout { spacing: 0 Rectangle { Layout.fillWidth: true Layout.horizontalStretchFactor: 2 Layout.preferredWidth: parent.width * 2 / 3 Layout.fillHeight: true color: color.neutral opacity: 0.7 } Rectangle { Layout.fillWidth: true Layout.horizontalStretchFactor: 1 Layout.preferredWidth: parent.width / 3 Layout.fillHeight: true color: color.dialog } }
However in this case fillWidth and horizontalStretchFactor are unnecessary.