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. Invert ListView without filling the ListView from the bottom
Qt 6.11 is out! See what's new in the release blog

Invert ListView without filling the ListView from the bottom

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.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.
  • Q Offline
    Q Offline
    qwasder
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • shavS Offline
      shavS Offline
      shav
      wrote on last edited by
      #2

      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.

      Mac OS and iOS Developer

      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