Details
-
Bug
-
Resolution: Unresolved
-
P4: Low
-
None
-
5.15.0
-
None
Description
Sometimes it's necessary to keep an item "hidden" but still have its height accounted for in layouting. This can be done by setting maximumWidth to 0:
import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Layouts 1.15 Window { width: 640 height: 480 visible: true title: "rowLayout.width: " + rowLayout.width component Rect: Rectangle { color: "tomato" implicitWidth: 10 implicitHeight: 10 property bool shown: false Layout.maximumWidth: shown ? implicitWidth : 0 } RowLayout { id: rowLayout anchors.centerIn: parent spacing: 3 Rect {} Rect {} Rect {} } Rectangle { anchors.fill: rowLayout color: "transparent" border.color: "darkorange" } }
However, spacing will still be applied in this case, even though there are no non-zero width items, resulting in the layout's width being 6 instead of 0.
Even if there are some non-zero-width items and some that are zero-width, the zero-width should not be accounted for when applying spacing. E.g. making the following changes to the layout above should have a width of 23, not 26:
Rect { shown: true } Rect {} Rect { shown: true }
The workaround is to set spacing to 0 and manually space out the items (either through padding or margins), which is tedious.