Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.7.1
-
None
Description
Currently, the height of a StackLayout is always the height of its biggest child.
The Layout.fillHeight and Layout.fillWidth proprties of its child items default to true. See https://bugreports.qt.io/browse/QTBUG-59711
Now, if we want a StackLayout whose height automatically adapts to the height of its current child, it would be handy to have a simple property to allow that behaviour.
Here is an alternative simplified implementation that behaves as explained above:
/** * Custom implementation of a simplified StackLayout. * Its height adapts to the height of its current child. */ import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 ColumnLayout { property int count: children.length property int currentIndex: 0 onCurrentIndexChanged: { hideAllButCurrent(); } Component.onCompleted: { hideAllButCurrent(); } function hideAllButCurrent() { for (var i = 0; i < count; ++ i) { var child = children[i]; if (i == currentIndex) { child.visible = true; child.enabled = true; } else { child.visible = false; child.enabled = false; } } } }