qtqmlswipeview

QML Swipeview no animation


Is it possible to remove the animation from swipeviews? The one where you see the transition from the previous and the next page. I have many pages and I have a menu that selects the active item like:

mainContent.setCurrentIndex(0)

where mainContent is the swipeview.

    // The content changes based on what is clicked on in the menu
    SwipeView{
        width: mainWindow.width - mainMenuId.width -anchors.leftMargin
        id:mainContent
        anchors.leftMargin:  20
        anchors.topMargin: 20
        clip:true
        Component.onCompleted: contentItem.interactive = false
        currentIndex: 0

        Item{PageMain{}}                 
        Item{PageTests{}}             
        Item{PageData{}}                                
        Item{PageSavedFiles{}}                          
        Item{PageProbe{}}                               

}

Solution

  • Either you can override the contentItem and disable ListView's animation, or, if you don't really need the swipe part of SwipeView, use e.g. StackLayout instead:

    TabBar {
        id: bar
        width: parent.width
        TabButton {
            text: qsTr("Home")
        }
        TabButton {
            text: qsTr("Discover")
        }
        TabButton {
            text: qsTr("Activity")
        }
    }
    
    StackLayout {
        width: parent.width
        currentIndex: bar.currentIndex
        Item {
            id: homeTab
        }
        Item {
            id: discoverTab
        }
        Item {
            id: activityTab
        }
    }
    

    That code is using TabBar, but I think you get the idea. :)