Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › Add Timer to SwipeView to make 'Slideshow'

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #19079

    Edward

    I have 3 or 4 images/Videos in a SwipeView,

    I would like to add a timer to these so they automatically move to the next after chosen interval and then loop back around at the end, my current code is below, what would I add/adjust to allow this to happen,

        Quick2.SwipeView {
            id: slideshow
            width: parent.width
            height: dp(200)
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: parent.top
    
            Item {
                AppImage {
                    fillMode: Image.PreserveAspectFit
                    anchors.fill: parent
                    source: "../assets/image1.png"
                }
            }
            Item {
                AppImage {
                    fillMode: Image.PreserveAspectFit
                anchors.fill: parent
                source: "../assets/image2.bmp"
            }
        }
            Item {
                MediaPlayer {
                        id: mediaplayer
                        autoPlay: true
                        loops: MediaPlayer.Infinite
                        source: "../assets/video1.mov"
                      }
    
                      VideoOutput {
                        anchors.fill: parent
                        source: mediaplayer
                      }
            }
    
        Item {
            AppImage {
                fillMode: Image.PreserveAspectFit
                anchors.fill: parent
                source: "../assets/image3.png"
            }
        }
        }

     

    #19083

    Günther
    Felgo Team

    Hi Edward,

    you can have a look at the SwipeView documentation here: https://doc.qt.io/qt-5.10/qml-qtquick-controls2-swipeview.html#index-attached-prop

    When choosing “list of all members, including inherited members“, you get a full list of all available properties and functions: https://doc.qt.io/qt-5.10/qml-qtquick-controls2-swipeview-members.html

     

    You can see that you can access the currentIndex property, or modify it with setCurrentIndex. You can use this with a Timer to auto-switch the shown image:

    Timer {
        running: true
        repeat: true
        interval: 2000
        onTriggered: {
          var nextIndex = (slideshow.currentIndex + 1) % slideshow.count
          console.log("NEXT: "+nextIndex)
          slideshow.setCurrentIndex(nextIndex)
        }
      }

     

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded