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

ListView reset position to begining when the proxy model sort called

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15, 6.8
    • None
    • All

    Description

      When we use the following chain of models && listview:

      source -> proxy -> listview

      and do call the proxy->sort(), then all fine, the listview position stays same (scroll stays same).

      But, when we use the following chain of models && listview:

      source -> proxy1 -> proxy2 -> listview

      and do call the proxy1->sort() then all breaks, the listview position resets to the beginning (scroll resets to beginning)

      Why this happens, and how to stay the position same? This happens with all Qt versions from up 5.x to 6x.

      This example demonstrates a problem:

      Window {
          width: 400
          height: 400
          visible: true
          title: qsTr("Hello World")
      
          MyListModel { id: sm }
          MyProxyModel { id: pm1; sourceModel: sm }
          MyProxyModel { id: pm2; sourceModel: pm1 }
      
          ColumnLayout {
              anchors.fill: parent
              ListView {
                  id: lview
                  currentIndex: -1
                  clip: true
                  spacing: 0
                  highlightFollowsCurrentItem: false
      
                  model: pm2
                  delegate: ItemDelegate {
                      text: model.id
                      highlighted: ListView.isCurrentItem
                      onClicked: lview.currentIndex = index
                  }
                  Layout.fillWidth: true
                  Layout.fillHeight: true
                  ScrollBar.vertical: ScrollBar {}
              }
      
              Button {
                  text: "Sort"
                  onClicked: pm1.doSort() // << We need to call exactly pm1 sort!!!
                  Layout.fillWidth: true
              }
          }
      }
      

      How to reproduce an issue:

      1. Compile && run the application
      2. Scroll to somewhere (e.g. to end)
      3. Click to "Sort" button
      4. Watch for the view reset up the beginning (with the scroll).

      If to change the listview model to `pm1` and then call `pm1->sort()` then this bug does not happens.

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            kuzulis Denis Shienkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes