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

SwipeView: Visual page not equal to currentIndex after insert

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2, 6.2.3
    • Quick: Controls 2
    • None
    • Linux/X11, macOS

    Description

      The SwipeView (or more precise: the underlying container) is implemented in a way that whenever a new page is added to the SwipeView the view will keep the previously displayed page. If the page is added at an index lower or equal to the current one this happens by incrementing the currentIndex. So far so good.

      Problematic code segment:

      import QtQuick 2.15
      import QtQuick.Controls 2.15
      import QtQuick.Window 2.15
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Swipe Demo")
      
          Item {
              anchors.fill: parent
              SwipeView {
                  anchors.fill: parent
      
                  id: view
      
                  onCurrentIndexChanged: {
                      console.log("current index is set to: " + currentIndex)
                  }
      
                  Rectangle {
                      color: "blue"
                  }
                  Rectangle {
                      color: "red"
                  }
                  Component.onCompleted: {
                      contentItem.highlightMoveDuration = 0
                      contentItem.highlightMoveVelocity = -1
                  }
              }
          }
      
          Rectangle {
              id: rect
              color: "green"
          }
      
          Row {
              anchors.bottom: parent.bottom
              anchors.right: parent.right
              Button {
                  text: "Add at Idx 0"
                  onClicked: {
                      view.insertItem(0, rect)
                  }
              }
              Button {
                  text: "Jump to Idx 0"
                  onClicked: {
                      view.setCurrentIndex(0)
                  }
              }
              Button {
                  text: "Jump to Idx 1"
                  onClicked: {
                      view.setCurrentIndex(1)
                  }
              }
          }
      }
      

      Correct behavior:

      • Start the application and swipe between the blue and red page (using mouse or touch)
      • Make sure to end at the blue page (index 0)
      • Push "Add at Idx 0"
      • The currentIndex is updated to 1 and the blue page still in frame
      • You can now swipe to the newly inserted page and the currentIndex is updated to 0

      Incorrect behavior:

      • Start the application and swipe to the red page
      • Click "Jump to Index 0", this displays the blue page
      • Push "Add at Idx 0"
      • The currentIndex is updated to 1 and the newly inserted green page is shown.

      This is incorrect as the newly inserted page has index 0. I'd expect the same behavior as above: The currentIndex would be updated to 1 and the blue page should still be displayed.

      In my example I'm using setCurrentIndex(). The resulting behavior is the same as by setting directly currentIndex.

      Fun fact:

      If the red page (Index 1) is displayed while inserting the green page at index 0, it's working correctly in both cases: The currentIndex is updated to 2 and the red page stays in view.

       

      Is there any workaround for this problem?

      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
            thomas_kopp Thomas Kopp
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes