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. Change Item in ListView in a time interval
Forum Updated to NodeBB v4.3 + New Features

Change Item in ListView in a time interval

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 2.9k 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.
  • V Offline
    V Offline
    vitorcarvalhoml
    wrote on last edited by
    #1

    How can I change the showing item after a while?
    The interval could be set through a json file?

    Thanks ;)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      You can use "QTimer":https://qt-project.org/doc/qt-5/qtimer.html#details

      @
      QTimer *timer = new QTimer(this);
      connect(timer, SIGNAL(timeout()), this, SLOT(updateListView()));
      timer->start(1000);
      @

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vitorcarvalhoml
        wrote on last edited by
        #3

        It's possible to solve this problem just using QML? Or QML and Javascript?
        Thanks for your quickly answer! ;)

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xander84
          wrote on last edited by
          #4

          hi, there is a QML Timer object wrapper for QTimer, so yes you can use the timer in QML without any c++: http://qt-project.org/doc/qt-5.0/qtqml/qml-qtquick2-timer.html

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vitorcarvalhoml
            wrote on last edited by
            #5

            Hi, thank you!

            I tried your solution. But I'm quite newbie. Here what i'm trying to do.

            @Item {
            id: root
            property string name
            property bool isSelected: listView.currentIndex === index
            Timer {
            interval: 5000; running: true; repeat: true
            onTriggered: listView.currentIndex = currentIndex + 1
            }@

            When I run the file, I got this error:

            [...] SlideItem.qml:11: ReferenceError: currentIndex is not defined

            ps 1.: I am changing the Cinematic Experience (http://quitcoding.com/?page=work)

            ps 1.: What I'm trying to do is a slideshow program

            1 Reply Last reply
            0
            • X Offline
              X Offline
              Xander84
              wrote on last edited by
              #6

              currentIndex should work if your listView ID is correct!? weird

              but I guess you need that inside of the delegate of the ListView? then you should use the attached property "isCurrentItem":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-listview.html#isCurrentItem-prop anyways.

              Also you can use "listView.incrementCurrentIndex()":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-listview.html#incrementCurrentIndex-method instead of "listView.currentIndex = currentIndex + 1". :)

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vitorcarvalhoml
                wrote on last edited by
                #7

                Thank you for the tip!

                In my MainView.qml I set the listView ID
                @ListView {
                id: listView

                        // property real globalLightPosX: lightImage.x / root.width
                        // property real globalLightPosY: lightImage.y / root.height
                
                        // Normal-mapped cover shared among delegates
                        // ShaderEffectSource {
                        //     id: coverNmapSource
                        //     sourceItem: Image { source: "images/cover_nmap.png" }
                        //     hideSource: true
                        //     visible: false
                        // }
                
                        anchors.fill: parent
                        // spacing: -60
                        model: slidesModel
                        delegate: SlideItem {
                            name: model.name
                        }
                        highlightFollowsCurrentItem: true
                        highlightRangeMode: ListView.StrictlyEnforceRange
                        highlightMoveDuration: 400
                        // preferredHighlightBegin: root.height * 0.5 - 140
                        // preferredHighlightEnd: root.height * 0.5 - 140
                        cacheBuffer: 4000
                    }@
                

                Thats correct right?
                I do not understand the use of isCurrentItem in my case.

                ---- EDIT----
                Hey! It works when I changed to listView.incrementCurrentIndex()
                But it jumps to a item that it's not the next one.

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vitorcarvalhoml
                  wrote on last edited by
                  #8

                  Hi again!

                  I notice that the next item when the interval ends, it's the fifth element item. How can I correct this? It's very strange because I'm using incrementCurrentIndex() method.

                  1 Reply Last reply
                  0

                  • Login

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