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

QML components which have model / delegate reset when model is updated

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.14.1
    • Quick: Other
    • None

    Description

      Repeater, ListView kind of components which have model / delegate structure are completely resetting when an element within array is modified.

      At the example below, the delegate is "Button and it's own Popup".

      First, hover your mouse on the button, you will see that button is having the hover effect, changing color etc. Then two seconds later, when Timer is triggered, that hover effect will reset.

      Second, click the button, Popup will open, then when Timer is triggered, Popup will close.

      I am not sure if this is a bug or not. If it isn't then please recommend me a way to have a list which I can modify the elements and it won't reset.

      import QtQuick 2.12
      import QtQuick.Window 2.12
      import QtQuick.Controls 2.12
      
      Window {
          id: window
          width: 300
          height: 300
          color: "black"
      
          property var array: ([0])
      
          Timer {
              running: true
              repeat: true
              interval: 2000
              onTriggered: {
                  ++array[0]
                  // Value won't change if it's not set to itself
                  array = array
              }
          }
      
          // All "Item"s are being fully reset, at every update
          // the hover effect on button disappears,
          // and modal is being closed
          Repeater {
              model: array
              delegate: Item {
                  Button {
                      text: "Open My Popup"
                      onClicked: modal.open()
                  }
      
                  Popup {
                      id: modal
                      anchors.centerIn: Overlay.overlay
                      modal: true
      
                      Text {
                          text: model.modelData
                          color: "white"
                      }
                  }
              }
          }
      }
      

      Attachments

        Issue Links

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

          Activity

            People

              w00t Robin Burchell
              naezith Tolga Ay
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes