Important: Please read the Qt Code of Conduct -

Scroll ListView from code

  • Is it possible to scroll my listView from code like on button press.
    I tried to follow the following link:
    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.


  • 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)

Log in to reply