Reload items of ListView: selected item index resets too
I have a QML listview and a C++ derived AbstractListModel connected to it.
- I load the QML Listview with items of my derived AbstractListModel.
- User decides to delete the selected item by pressing a button. So I tell the LDAP server to delete the item.
- I remove all my items from my derived AbstractListModel and call the reset() method because the list is cleared.
- Now the QML Listview is empty and the selected cursor is gone.
- 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).
- 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...
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.