Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-73078

StackLayout: Missing layout update when dynamically adding items with Repeater

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.0
    • Quick: Layouts
    • 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
            }
          }
        }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            njeisecke Nils Jeisecke
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes