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. Here is the code:
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
ColumnLayout {
anchors.fill: parent
Rectangle {
Layout.fillHeight: true
Layout.fillWidth: true
Layout.verticalStretchFactor: 1
border.color: "red"
}
Rectangle {
Layout.fillHeight: true
Layout.fillWidth: true
Layout.verticalStretchFactor: 2
border.color: "blue"
}
}
}
The same problem for Layout.horizontalStretchFactor. I am using Qt 6.7.2. Is there anything wrong?
0
Sounds like a bug. That works but only if you set Layout.preferredHeight
and Layout.maximumHeight
to some values.
As a workaround you can set it to:
ColumnLayout {
anchors.fill: parent
spacing: 0
Rectangle {
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredHeight: 1
Layout.maximumHeight: 1000
Layout.verticalStretchFactor: 1
color: "red"
}
Rectangle {
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredHeight: 1
Layout.maximumHeight: 1000
Layout.verticalStretchFactor:2
color: "blue"
}
}
1