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. How to set Tumbler (Controls 2) currentIndex without animation?
Forum Update on Monday, May 27th 2025

How to set Tumbler (Controls 2) currentIndex without animation?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 3.5k Views
  • 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.
  • D Offline
    D Offline
    David K. Hess
    wrote on last edited by
    #1

    Is there a supported way to load a value into Tumbler (i.e. set currentIndex) without the animation? This is needed for forms where you need to "edit" existing values.

    I've looked at the source code to Tumbler and it doesn't appear there is a way.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      David K. Hess
      wrote on last edited by
      #6

      @6thC thanks for the hint. I was able to come up with a pretty simple work-around:

      1. Use the ListView option under Customizing Tumbler: https://doc.qt.io/qt-5.10/qtquickcontrols2-customize.html#customizing-tumbler
      Tumbler {
          id: tumbler
      
          contentItem: ListView {
              model: tumbler.model
              delegate: tumbler.delegate
      
              snapMode: ListView.SnapToItem
              highlightRangeMode: ListView.StrictlyEnforceRange
              preferredHighlightBegin: height / 2 - (height / tumbler.visibleItemCount / 2)
              preferredHighlightEnd: height / 2 + (height / tumbler.visibleItemCount / 2)
              clip: true
          }
      }
      
      1. Do exactly what you described:
      tumbler.contentItem.positionViewAtIndex(newIndex, ListView.Center);
      tumbler.currentIndex = newIndex;
      

      Works perfectly and looks exactly the same.

      1 Reply Last reply
      1
      • D Offline
        D Offline
        David K. Hess
        wrote on last edited by
        #2

        I basically need this for Tumbler:

        http://doc.qt.io/qt-5/qml-qtquick-listview.html#positionViewAtIndex-method

        Unfortunately, the underlying ListView used by Tumbler is a private property of the TumblerView (itself a private object).

        1 Reply Last reply
        0
        • 6thC6 Offline
          6thC6 Offline
          6thC
          wrote on last edited by
          #3

          Yes, you won't have a lot of fun doing anything other than what a tumbler does I found.

          You can reuse Tumbler code. (not having to rethink the styling/get a head start for similar look and feel is nice).

          Then do as you were planning:

          // instant update view
          listView.positionViewAtIndex (newIndex, ListView.Center);
          // actually set index
          ...currentIndex= newIndex;
          

          I ended up making my own components from ListViews and PathViews depending on what I needed.

          D 1 Reply Last reply
          0
          • 6thC6 6thC

            Yes, you won't have a lot of fun doing anything other than what a tumbler does I found.

            You can reuse Tumbler code. (not having to rethink the styling/get a head start for similar look and feel is nice).

            Then do as you were planning:

            // instant update view
            listView.positionViewAtIndex (newIndex, ListView.Center);
            // actually set index
            ...currentIndex= newIndex;
            

            I ended up making my own components from ListViews and PathViews depending on what I needed.

            D Offline
            D Offline
            David K. Hess
            wrote on last edited by
            #4

            @6thC thanks for the feedback. I'm going to open a bug on it.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              David K. Hess
              wrote on last edited by
              #5

              FYI, opened: QTBUG-66358

              https://bugreports.qt.io/browse/QTBUG-66358

              1 Reply Last reply
              1
              • D Offline
                D Offline
                David K. Hess
                wrote on last edited by
                #6

                @6thC thanks for the hint. I was able to come up with a pretty simple work-around:

                1. Use the ListView option under Customizing Tumbler: https://doc.qt.io/qt-5.10/qtquickcontrols2-customize.html#customizing-tumbler
                Tumbler {
                    id: tumbler
                
                    contentItem: ListView {
                        model: tumbler.model
                        delegate: tumbler.delegate
                
                        snapMode: ListView.SnapToItem
                        highlightRangeMode: ListView.StrictlyEnforceRange
                        preferredHighlightBegin: height / 2 - (height / tumbler.visibleItemCount / 2)
                        preferredHighlightEnd: height / 2 + (height / tumbler.visibleItemCount / 2)
                        clip: true
                    }
                }
                
                1. Do exactly what you described:
                tumbler.contentItem.positionViewAtIndex(newIndex, ListView.Center);
                tumbler.currentIndex = newIndex;
                

                Works perfectly and looks exactly the same.

                1 Reply Last reply
                1
                • _ _-Peter-_ referenced this topic on

                • Login

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