Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML ListView scroll to last added item
Forum Updated to NodeBB v4.3 + New Features

QML ListView scroll to last added item

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 4.2k Views 1 Watching
  • 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
    supaiku_
    wrote on last edited by supaiku_
    #1

    Hi,

    I can't figure out how to make a ListView always scroll to the last added item.

    I have a ListView and a ListModel. Once the ListModels grows, the ListView instantiates items.
    That's good. But it does not automatically "focus" or scroll down if the item is outside the viewport.

    How do I do that?
    My initial attempt was to call view.positionViewAtEnd() in the onCountChanged of the
    ListView. But it does not work reliable. If I call that in the delegates
    Component.onCompleted Qt segfaults.

    I'm using Qt 5.5 and Qt 5.6.

    Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      One possible way to do it:

      Timer {
          id: positionTimer
          interval: 200
          repeat: false
          onTriggered: view.positionViewAtIndex(view.count - 1, ListView.Visible)
      }
      
      onCountChanged: {
          positionTimer.start()
      }
      

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        supaiku_
        wrote on last edited by
        #3

        Works great. Even though it feels like a hack.

        Thanks a lot.

        1 Reply Last reply
        0

        • Login

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