Tree selection clears when data model refresh

66 Views Asked by At

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?

1

There are 1 best solutions below

1
Antriksh kakkar On

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