Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Swipe View getting stuck
Qt 6.11 is out! See what's new in the release blog

Swipe View getting stuck

Scheduled Pinned Locked Moved Solved QML and Qt Quick
11 Posts 3 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Anita

    I am using swipe view under which i have three qml's loaded in each page. Total no of pages are 5. One Qml has three waveforms displayed, which changes to 1 waveform in the next page. While Swiping the view, the view gets stuck in between. Is there a signal or function to know if the swipe view has completed the swipe(i.e the page is moved to the next page)?

    J.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on last edited by
    #2

    hi @Anita

    currentIndex and/or currentItem should change only after the transition finished.
    So you can listen/react to the onCurrentIndexChanged: signal


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    IntruderExcluderI 1 Reply Last reply
    0
    • A Offline
      A Offline
      Anita
      wrote on last edited by
      #3

      @J-Hilk said in Swipe View getting stuck:

      onCurrentIndexChanged

      @J-Hilk Currently i have used a repeater for the 5 pages of the swipeview.
      Can i load a page dynamically after the current index has changed? and is there a signal to indicate a start of the swipe as well?

      J.HilkJ 1 Reply Last reply
      0
      • A Anita

        @J-Hilk said in Swipe View getting stuck:

        onCurrentIndexChanged

        @J-Hilk Currently i have used a repeater for the 5 pages of the swipeview.
        Can i load a page dynamically after the current index has changed? and is there a signal to indicate a start of the swipe as well?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #4

        @Anita
        sure:

        import QtQuick 2.12
        import QtQuick.Controls 2.12
        import QtQuick.Window 2.2
        
        Window {
            visible: true
            width: 400
            height: 100
            title: qsTr("Hello World")
        
            id:window
        
            Component {
                id:myComponent
                Rectangle{
                    property alias pageIndex: name.text
                    Component.onCompleted: console.log("Just completed")
                    Component.onDestruction: console.log("Destructed", pageIndex)
                    Text {
                        id: name
                        anchors.centerIn: parent
                        onTextChanged: console.log("new text:", text)
                    }
                }
            }
        
            SwipeView{
                id:swipeView
                anchors.fill: parent
        
                Repeater{
                    model: 10
                    delegate: Loader{
                        active: index === swipeView.currentIndex
                        onLoaded: item.pageIndex = index
                        sourceComponent: myComponent
                    }
                }
            }
        }
        

        and is there a signal to indicate a start of the swipe as well

        That, I'm unsure about


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Anita
          wrote on last edited by
          #5

          @J-Hilk Thank you. I will use currentIndex to know if the transition has been completed.

          1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            hi @Anita

            currentIndex and/or currentItem should change only after the transition finished.
            So you can listen/react to the onCurrentIndexChanged: signal

            IntruderExcluderI Offline
            IntruderExcluderI Offline
            IntruderExcluder
            wrote on last edited by
            #6

            @J-Hilk said in Swipe View getting stuck:

            currentIndex and/or currentItem should change only after the transition finished.
            So you can listen/react to the onCurrentIndexChanged: signal

            This seems isn't true. Here is an example, which illustrates that current index of view changes before swipe transition ends:

                SwipeView {
                    anchors.fill: parent
            
                    onCurrentIndexChanged: console.log("CURRENT INDEX", currentIndex)
            
                    Rectangle { color: "red"; opacity: 0.5 }
                    Rectangle { color: "green"; opacity: 0.5 }
                    Rectangle { color: "blue"; opacity: 0.5 }
            
                    Component.onCompleted: {
                        contentItem.flickEnded.connect(() => console.log("FLICK ENDED"));
                    }
                }
            
            J.HilkJ 1 Reply Last reply
            1
            • A Offline
              A Offline
              Anita
              wrote on last edited by
              #7

              @IntruderExcluder
              Thanks for this solution, this helped me solve the issue.

              1 Reply Last reply
              0
              • IntruderExcluderI IntruderExcluder

                @J-Hilk said in Swipe View getting stuck:

                currentIndex and/or currentItem should change only after the transition finished.
                So you can listen/react to the onCurrentIndexChanged: signal

                This seems isn't true. Here is an example, which illustrates that current index of view changes before swipe transition ends:

                    SwipeView {
                        anchors.fill: parent
                
                        onCurrentIndexChanged: console.log("CURRENT INDEX", currentIndex)
                
                        Rectangle { color: "red"; opacity: 0.5 }
                        Rectangle { color: "green"; opacity: 0.5 }
                        Rectangle { color: "blue"; opacity: 0.5 }
                
                        Component.onCompleted: {
                            contentItem.flickEnded.connect(() => console.log("FLICK ENDED"));
                        }
                    }
                
                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #8

                @IntruderExcluder
                uh, interesting.
                Hard to tell, this would require a deeper dive into the source code. To see, when what signal is emitted when exactly 🤔


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                0
                • IntruderExcluderI Offline
                  IntruderExcluderI Offline
                  IntruderExcluder
                  wrote on last edited by
                  #9

                  Keep in mind, that there is different logic between changing index programmatically and by user interaction. The question is why it is made so? I didn't get it, too complicated.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Anita
                    wrote on last edited by
                    #10

                    @IntruderExcluder ,
                    yes the current index changes before the flick has been ended.
                    but i there a property to get to know if the flick has been done in a positive or a negative direction?

                    1 Reply Last reply
                    0
                    • IntruderExcluderI Offline
                      IntruderExcluderI Offline
                      IntruderExcluder
                      wrote on last edited by
                      #11

                      You can define additional property, like:

                          SwipeView {
                              anchors.fill: parent
                      
                              currentIndex: 0
                              property int lastIndex: 0
                              onCurrentIndexChanged: {
                                  if (currentIndex > lastIndex) {
                                      console.log("INCREASED");
                                  } else {
                                      console.log("DECREASED");
                                  }
                                  lastIndex = currentIndex;
                              }
                      
                              Rectangle { color: "red"; opacity: 0.5 }
                              Rectangle { color: "green"; opacity: 0.5 }
                              Rectangle { color: "blue"; opacity: 0.5 }
                          }
                      
                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved