-1

I have a treeview in which I have applied sorting/filtering using QSortFilterProxyModel.

When I perform some action on tree item(ex. RMB action), I refresh my data model(QAbstractItemModel).

I am using beginresetmodel() before refreshing my data model. After data model's refreshed, selection on selected item disappears. I have saved the selections before refreshing data model, and applied them back after the model is refreshed, but the items do not get selected.

I tried removing beginResetModel() before refreshing data model, and selection works fine in that case.

QSortFilterProxyModel documentation says:

However, beginResetModel() / endResetModel() returns the proxy model to its original state, losing selection information, and will cause the proxy model to be repopulated."

How can I retain selection while keeping beginResetModel() / endResetModel() when refreshing data model?

  • Details can be found in this thread on Qt Forum: [tree selection clears when data model refresh](https://forum.qt.io/topic/145241/tree-selection-clears-when-data-model-refresh/9?_=1684739336924) – Abderrahmene Rayene Mihoub May 22 '23 at 07:13

1 Answers1

-1

I am able to fix this by refreshing the seleced rows instead of reloading complete data model.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 22 '23 at 07:02