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

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

    XMLWordPrintable

Details

    • 37c25c6e7 (dev), 8fae0aa4a (6.5)

    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

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There is 1 open Gerrit change