ListView overshoot limit
-
Is there any way to restrict user from infinite overshoot when flicking? I want to implement android-like refresh for
ListView
, problem is that I want to set some sort of maximum for vertical overshooting, but I do not see any property for that.Any ideas? Maybe I'm missing something?
-
contentHeight?
as an 'inherited member' of ListView: https://doc.qt.io/qt-5/qml-qtquick-flickable.html#contentHeight-prop
-
Didn't get your idea. I mean I have an
ListView
with default bounds behaviour. Being at top of list I can drag its contents to a bottom direction, to simulate refresh request, like it is made in Android. The problem here is that I cannot restrict bottom dagging distance. Another problem is that I don't know ho to properly reset mouse grab. -
Ok, just made it with a bit of C++ magic.
ListView { readonly property real maxOvershoot: 100 property bool resetting: false boundsBehavior: contentY > 0 ? ListView.StopAtBounds : ListView.DragOverBounds // Overbound draggind allowed only at top of list model: 20 onVerticalOvershootChanged: { if (Math.abs(verticalOvershoot) >= maxOvershoot && !resetting) { resetting = true; returnToBounds(); Test.ungrab(this); // C++ grab trick } } onContentYChanged: { if (contentY === 0.0 && resetting) { resetting = false; } } delegate: Rectangle { ... } }
And C++ code is quite simple:
Q_INVOKABLE void ungrab(QQuickItem* list) { if (list != nullptr) { list->ungrabMouse(); list->ungrabTouchPoints(); } }