ListView - insert item above existing one -> DO NOT move/push down the existing/clicked one



  • Hi gurus!
    So there is a pretty QML ListView with e.g. 10 items. Let's say, 5 of them are visible. Now I click on the last visible item(index=4) in this list and by doing this, a brand new item will be inserted above(just before) the clicked one. I would like my 5th item (that I just clicked) NOT TO MOVE down, but stay VISIBLE. List should move one item up. See the desired behaviour on the sketch attached.
    Any ideas how to achieve that?

    0_1499149535079_listview.jpg

    thanks+cheers
    Simon :-)


  • Moderators

    @Szymon
    either use

    ListView {
        preferredHighlightBegin: ...
        preferredHighlightEnd: ...
        highlightRangeMode: ListView.StrictlyEnforceRange
    }
    

    to manually scroll to a position.

    Or use ListView.positionViewAtIndex() method to ensure that a index is visible in the view.



  • @raven-worx
    Yes, thak you! Once I posted the message the solution with:

    positionViewAtIndex(index+1, ListView.Visible);
    

    just came up to me like a flash. I knew this method and used it in the past successfully already. But somehow couln't see wood for the trees ;)
    However the highlight method - this I will have to try out either.

    PS. the index has to be set dynamically of course. This "+1" is only an example...

    cheers
    Simon :-)


Log in to reply
 

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