Unsolved Qml flickable disable scroll inertia
-
I want to make a flickable-listview to be only scrollable via the mouse wheel or up/down buttons on the scrollbar. I would also like to disable the scroll momentum/inertia that the flickable has so it behaves properly when scrolling in big lists with the scroll wheel and doesn't feel like a touch device.
-
Hi!
MyListView.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 Rectangle { id: myListView clip: true focus: true property var model: null property int moveSpeed: 300 function moveContent(up) { listView.flick(0, up ? moveSpeed : -moveSpeed ) } ListView { id: listView anchors.fill: parent model: myListView.model delegate: Text { text: number + ": " + name } boundsBehavior: Flickable.StopAtBounds } MouseArea { anchors.fill: parent onWheel: myListView.moveContent( wheel.angleDelta.y>0 ) } Keys.onPressed: { if (event.key === Qt.Key_Up) { myListView.moveContent(true) event.accepted = true } else if (event.key === Qt.Key_Down) { myListView.moveContent(false) event.accepted = true } else { event.accepted = false } } }
main.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World") ListModel { id: myModel Component.onCompleted: { for (var i=0; i<50; ++i) append({"number": i, "name":"Pizza"}) } } MyListView { model: myModel color: "orange" anchors.fill: parent } }
-
It doesn't work as expected, at first is too slow, but when making the move speed around 1200 it still has inertia, not as much but still annoying. Is there any trick to always get the pixelDelta?
-
First you should set the property interactive to false (true by default).
Then you will have to force the flickable to move (when pressing a button, or when moving the mouse wheel event, for example) by incrementing/decrementing the contentX / contentY properties.
Hope it helps.