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

TableView: Reducing size causes delegates to be destroyed even when reuseItem==true

XMLWordPrintable

      Code

      import QtQuick
      import QtQuick.Controls.Basic
      import Qt.labs.qmlmodels
      
      Window {
          width: 640
          height: 480
          visible: true
      
          TableView {
              anchors.fill: parent
              reuseItems: true
              model: TableModel {
                  id: tableModel
                  TableModelColumn { display: "A" }
                  TableModelColumn { display: "B" }
                  TableModelColumn { display: "C" }
              }
              delegate: Rectangle {
                  id: delegate
                  implicitWidth: 100
                  implicitHeight: 100
                  border.width: 1
                  
                  required property string modelData
      
                  Text {
                      text: delegate.modelData
                      font.pointSize: 18
                      anchors.centerIn: parent
                  }
      
                  TableView.onPooled: console.log("Pooled", delegate.modelData)
                  TableView.onReused: console.log("Reused", delegate.modelData)
                  Component.onCompleted: console.log("Constructed", delegate.modelData)
                  Component.onDestruction: console.log("Destroyed", delegate.modelData)
              }
          }
          Component.onCompleted: {
              let rows = []
              for (let i = 0; i < 3; ++i) {
                  rows.push({
                      "A": `(${i}, 0)`,
                      "B": `(${i}, 1)`,
                      "C": `(${i}, 2)`
                  })
              }
              tableModel.rows = rows
          }
      }
      

       

      Steps to reproduce

      1. Run the code above
      2. Shrink the window to be as close to 0x0 as possible
      3. Enlarge the window again to allow all delegates to fit in the window

       

      Expected outcomes

      • Step 2: All delegates get pooled
      • Step 3: All delegates get reused

       

      Actual outcomes

      • Step 2: All delegates get pooled and then get destroyed
      • Step 3: All delegates get re-constructed from scratch

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

            richard Richard Moe Gustavsen
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes