Updating ListView selection when a model resets
-
I am completely reseting a model derived from QAbstractListModel. I need to set the current selection when the model updates. Currently, the currentItem returns null. I can't seem to find a documented way to capture a signal from the model and do some custom stuff on the view.
-
Hi,
Do you mean connect to the modelAboutToBeReset to do some stuff ?
-
Well depending on what you have in mind, you should connect to both. Typically, if you want to store something like the content of the currently selected item to try and reselect it after the model was updated, you would need to do it following modelAboutToBeReset because modelReset is called once everything is done on the "reset" part.
-
Well depending on what you have in mind, you should connect to both. Typically, if you want to store something like the content of the currently selected item to try and reselect it after the model was updated, you would need to do it following modelAboutToBeReset because modelReset is called once everything is done on the "reset" part.
So I have a listview, call that A, that connects to the custom model. I use onComplete when it first loads to to position the view at index 0, onChangeIndex to update my a c++ class with the selection.
Not sure if this is the best method. But I am dealing with a spinner like gui element and this seemed the best way to get the element that falls in the spinner's "selected" area. (Not really a selection, but when it falls inside the gui spinner's "focus" box).
When I change a different listview (view B), I completely refresh the data in ListView A. I need to set the index again. Or do something to update my c++ class. It seems after refresh, currentItem becomes null, because it no longer exists. So I am trying to find a way to connect to the modelReset in order to make sure currentItem has the top most index in it. I tried using Connections to connect to the ListView's model property. But that simply told be onResetModel was not there (forget the actual error).
-
Are you using QML for your GUI ?
-
In that case, wouldn't it be simple to take the original humbler code and modify it to look like you want ?