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. ListView - insert item above existing one -> DO NOT move/push down the existing/clicked one
Qt 6.11 is out! See what's new in the release blog

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

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

    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 :-)

    raven-worxR 1 Reply Last reply
    0
    • S Szymon

      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 :-)

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

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

        @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 :-)

        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