Scroll ListView from code
Solved
Qt for MCUs
-
wrote on 7 Jul 2020, 11:13 last edited by
Is it possible to scroll my listView from code like on button press.
I tried to follow the following link:
https://forum.qt.io/topic/107092/how-to-scroll-listview-from-code-in-qml/2
But several features which basically helps in scrolling from code are missing from QTMCU version, like flick()How to achieve this in QTforMCU
Can I see an example for that.-Thanks
-
wrote on 10 Jul 2020, 09:31 last edited by
You could programmatically change the contentX and contentY properties of the ListView and use a Behavior to animate the change of these properties.
Here is a small example:
import QtQuick 2.0 import QtQuick.Controls 2.0 Rectangle { width: 480 height: 272 ListView { id: list width: 380 height: 480 interactive: false Behavior on contentY { NumberAnimation { duration: 500 easing.type: Easing.OutCubic } } model: 30 delegate: Text { height: 40 width: list.width verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter text: index } } Button { id: button anchors.right: parent.right height: 272 width: 100 text: "Scroll!" onClicked: list.contentY = (list.contentY === 0 ? -300 : 0) } }
1/2