QML ListView scroll to last added item



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


  • Lifetime Qt Champion

    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



  • Works great. Even though it feels like a hack.

    Thanks a lot.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.