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

Binding delegate height to ListView height causes delegates to be created unnecessarily

    XMLWordPrintable

Details

    Description

      If Listview has a delegate with height binding to ListView, it creates all the delegate instances in the start and then delete them to keep only required ones.
      Please refer to the attached sample.

          ListView {
              id: listView
              anchors.fill: parent
              onHeightChanged: console.log("ListView height changed to:", height)
              model: listModel
              delegate: Rectangle {
                  width: listView.width / 2
                  height: listView.height
                  border.width: 1
                  radius: 10
                  Text {
                      anchors.centerIn: parent
                      text: name
                  }
                  Component.onCompleted: console.log("onCompleted:", ListView.view, index)
                  Component.onDestruction: console.log("onDestruction:", ListView.view, index)
              }
          }
      

      If Model has 7 items, the output is

      qml: onCompleted: QQuickListView(0x27e9478f000) 0
      qml: onCompleted: QQuickListView(0x27e9478f000) 1
      qml: onCompleted: QQuickListView(0x27e9478f000) 2
      qml: onCompleted: QQuickListView(0x27e9478f000) 3
      qml: onCompleted: QQuickListView(0x27e9478f000) 4
      qml: onCompleted: QQuickListView(0x27e9478f000) 5
      qml: onCompleted: QQuickListView(0x27e9478f000) 6
      qml: ListView height changed to: 480
      qml: onDestruction: QQuickListView(0x27e9478f000) 6
      qml: onDestruction: QQuickListView(0x27e9478f000) 5
      qml: onDestruction: QQuickListView(0x27e9478f000) 4
      qml: onDestruction: QQuickListView(0x27e9478f000) 3
      qml: onDestruction: QQuickListView(0x27e9478f000) 2
      

      Attachments

        1. qtbug89568.zip
          2 kB
          Shveta Mittal

        Issue Links

          Activity

            People

              mitch_curtis Mitch Curtis
              shmittal Shveta Mittal (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: