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

ListView items sometimes don't reposition correctly if content Y changes before the move

    XMLWordPrintable

Details

    Description

      For the following code:

      import QtQuick 2.0
      
      Item {
          width: 500; height: 500
      
          ListView {
              id: view2
              width: 300; height: 300
              y: 100
      
              model: ListModel {
                  id: model2
                  Component.onCompleted: {
                      for (var i=0; i<30; i++) {
                          append({'name': 'item ' + i})
                      }
                  }
              }
              delegate: Rectangle {
                  width: 100; height: 20; border.width: 0
                  Text { text: name + ": " + parent.y }
              }
      
              Component.onCompleted: {
                  //view2.contentY = 80
              }
          }
      
          focus: true
          Keys.onEnterPressed: view2.contentY = 80
          Keys.onReturnPressed: model2.move(0, 4, 1)
      
          Rectangle {
              anchors.fill: view2
              border.width: 1
              color: "transparent"
          }
      }
      

      Press 'Enter' to change the content y and then 'Return' to move 0 -> 4.

      The first 3 items are:

      item 3: 80
      item 4: 100
      item 0: 120

      when they should instead be:

      item 4: 80
      item 0: 100
      item 5: 120

      The problem doesn't occur if the contentY is set in ListView Component.onCompleted instead of the key press event.

      Attachments

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

        Activity

          People

            bealam Bea Lam (closed Nokia identity) (Inactive)
            bealam Bea Lam (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes