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

Changing delegates in DelegateModel not fully handled by views

    XMLWordPrintable

Details

    • 2d9cf3ef0fc09254b1a63ab04b86d9beb52e71bc (qt/qtdeclarative/5.15)

    Description

      The following example demonstrates the issue. Click any list item to change the delegate. Note the difference in behavior between the two alternatives:

      import QtQuick 2.0
      import QtQml.Models 2.2
      
      Item {
          width: 400
          height: 400
      
          property Component activeDelegate: yellowComponent
      
          Component {
              id: yellowComponent
      
              Rectangle {
                  width: parent.width
                  height: 50
                  color: "yellow"
      
                  MouseArea {
                      anchors.fill: parent
                      onClicked: activeDelegate = redComponent
                  }
              }
          }
      
          Component {
              id: redComponent
      
              Rectangle {
                  width: parent.width
                  height: 50
                  color: "red"
      
                  MouseArea {
                      anchors.fill: parent
                      onClicked: activeDelegate = yellowComponent
                  }
              }
          }
      
          ListView {
              id: listView
              anchors.fill: parent
              spacing: 1
      
              // WORKS: this version updates as expected: when clicking a delegate, all delegates are updated
              //model: 10
              //delegate: activeDelegate
      
              // DOESN'T: this version does not update as expected: when clicking a delegate, current delegates are not updated
              model: delegateModel
          }
      
          DelegateModel {
              id: delegateModel
      
              model: 10 // can also try with 100 for comparison (when scrolling, new delegates are correct, while cached ones are incorrect)
              delegate: activeDelegate
          }
      }
      
      

      Attachments

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

        Activity

          People

            srutledg Shawn Rutledge
            mbrasser Michael Brasser
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes