Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for MCUs
  4. Scroll ListView from code
Forum Update on Monday, May 27th 2025

Scroll ListView from code

Scheduled Pinned Locked Moved Solved Qt for MCUs
2 Posts 2 Posters 759 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sachin_Og
    wrote on 7 Jul 2020, 11:13 last edited by
    #1

    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

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      ylopes
      wrote on 10 Jul 2020, 09:31 last edited by
      #2

      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 Reply Last reply
      0

      1/2

      7 Jul 2020, 11:13

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved