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. Reload items of ListView: selected item index resets too
Forum Updated to NodeBB v4.3 + New Features

Reload items of ListView: selected item index resets too

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

    Hi,

    I have a QML listview and a C++ derived AbstractListModel connected to it.

    1. I load the QML Listview with items of my derived AbstractListModel.
    2. User decides to delete the selected item by pressing a button. So I tell the LDAP server to delete the item.
    3. I remove all my items from my derived AbstractListModel and call the reset() method because the list is cleared.
    4. Now the QML Listview is empty and the selected cursor is gone.
    5. I Now refill the list because I have received the new list from the LDAP server (it's the old list without the deleted item).
    6. I now have to reset the selected index to the previous index.

    When I jump back to the previous index you can see that the QML Listview jumps from the first index to the previous index.

    Is it possible to keep the previous index and reload the QML Listview so I don't see the jump from first to previous index? Unfortunately I always need to retrieve a complete new list from LDAP server so I cannot just change the selected item but have to retrieve the complete list...

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      I don't think you should be calling a full reset on the model. I only know the non-qml solution, but I'm assuming that it works the same. The model has a beginRemoveRows() and endRemoveRows() for this sorta work. It just notifies that one row is being removed. Make sure your internal data structure matches the external one and all will be fine.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      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