Forums

OverviewV-Play 2 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
    V-Play 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.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support