Solved How to set Tumbler (Controls 2) currentIndex without animation?
-
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.
-
@6thC thanks for the hint. I was able to come up with a pretty simple work-around:
- 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 } }
- Do exactly what you described:
tumbler.contentItem.positionViewAtIndex(newIndex, ListView.Center); tumbler.currentIndex = newIndex;
Works perfectly and looks exactly the same.
-
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).
-
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.
-
@6thC thanks for the feedback. I'm going to open a bug on it.
-
FYI, opened: QTBUG-66358
-
@6thC thanks for the hint. I was able to come up with a pretty simple work-around:
- 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 } }
- Do exactly what you described:
tumbler.contentItem.positionViewAtIndex(newIndex, ListView.Center); tumbler.currentIndex = newIndex;
Works perfectly and looks exactly the same.
-