Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.12.0
-
None
Description
Please try the follwing test case.
Without the workaround the StackedLayout won't adjust the size of the initial delegate (should have a red background). StackLayout will start working as expected after adding additional items or resizing the Window.
The ugly workaround is to trigger a size change of the layout once, in the example by fiddling with the anchor margin.
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Layouts 1.12 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") ListModel { id: lm // bug does not show if there is initally an element // ListElement { x: "y" } } StackLayout { id: l anchors { fill: parent topMargin: 20 } Repeater { id: rep model: lm delegate: Rectangle { color: "red" Text { text: "Index " + model.index } } } // ugly: workaround to trigger layout update // property bool __workaroundApplied // onCountChanged: { // if (!__workaroundApplied) { // __workaroundApplied = true // Qt.callLater(function() { // l.anchors.leftMargin = 1 // l.anchors.leftMargin = 0 // }) // } // } } Text { text: "click here to add entry (count: " + lm.count + " currentIndex: " + l.currentIndex + ")" TapHandler { onTapped: { lm.append({"x": "y"}) l.currentIndex = lm.count - 1 } } } }