qtqmlqt5

Qt qml SwipeView change animation/transition speed


I'm using Qt 5.10 and i'm using a SwipeView. I want to change the swipe animation speed, but after reading the docs i could not see how. Is there some workaround to do this?


Solution

  • the reason i was trying to do this was because, don't know why, the swipe transition animation was very slow (see below) this is my code:

    ColumnLayout{
            anchors.fill: parent
    
            Item{
                id:modulecontainer
    
                Layout.fillHeight: true
                Layout.fillWidth: true
    
                SwipeView{
                    id: moduleview
                    anchors.fill: parent
                    interactive: loggedUser.role==User.AdminRole
                    clip: true
                    orientation: Qt.Horizontal
                    Item {
                        id: firstPage
                        Loader {
                            anchors.fill: parent
                            id:moduleLoader
    
    
                        }
                    }
                    Item {
                        id: secondPage
                        Rectangle{
                            anchors.fill: parent
                            color: "red"
    
                        }
                    }
                 }
               }
          }
    

    enter image description here

    I solved this issue just taking the code of contentItem implementation from the source code of SwipeView:

      ....  
      SwipeView{
          id: moduleview
          ....
          contentItem: ListView {
                    model: moduleview.contentModel
                    interactive: moduleview.interactive
                    currentIndex: moduleview.currentIndex
    
                    spacing: moduleview.spacing
                    orientation: moduleview.orientation
                    snapMode: ListView.SnapOneItem
                    boundsBehavior: Flickable.StopAtBounds
    
                    highlightRangeMode: ListView.StrictlyEnforceRange
                    preferredHighlightBegin: 0
                    preferredHighlightEnd: 0
                    highlightMoveDuration: 250
                    //                    min:10
    
                    maximumFlickVelocity: 4 * (moduleview.orientation === 
                    Qt.Horizontal ? width : height)
                }
      }
      ....
    

    the result: enter image description here

    don't know why this solves the problem, but i'm sharing just in case others face the same problem. If more animation speed is wanted just replace the maximumFlickVelocity factor from 4 to a bigger value