Invert ListView without filling the ListView from the bottom



  • I want a ListView to invert the order of its items, so that the most recent item is at the top. I tried to achieve this using verticalLayoutDirection: ListView.BottomToTop, but it makes the ListView fill up from the bottom (as to be expected, I guess).

    Here's the code:
    @ListView
    {
    id: theList

    anchors
    {
        left: parent.left
        top: theAboveList.bottom
        right: parent.right
        bottom: parent.bottom
    }
    
    model: theModel
    delegate: theDelegate {}
    verticalLayoutDirection: ListView.BottomToTop
    clip: true
    

    }@

    Sorry, the stupid forum software won't let me post a screenshot, becaus it thinks URL == spam. Congrats on that strike of genius.

    How can I invert the ListView's item order and still have it fill from top to bottom? The cleaner, the better.



  • Hm....

    I think will be simple if you use invert model for ListView. For example if you have a model like (JSON):
    @
    [
    {"name":"Item1", ....},
    {"name":"Item2", ....},
    {"name":"Item3", ....}
    ]
    @

    you need to crate another array with structure:
    @
    [
    {"name":"Item3", ....},
    {"name":"Item2", ....},
    {"name":"Item1", ....}
    ]
    @

    And then use it in your ListView.


Log in to reply
 

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