Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Change filtered data representation in a tree using QStandardItemModel
giupigna last edited by
I have a tree structure using a QStandardItemModel. The model has only a rootItem and each item has one or more children. I added a search bar to find an item in the model.
Suppose to have this tree structure:
RootItem |_________ Item1 |_______Item 2 |_______Item 3 | |_________ Item4 |_______Item 3 | |_________ Item5
If the user searches the string "Item 3" what I want to do is to display the results in the same treeView in the following way:
RootItem |_________ Item1 |_______Item 3 RootItem |_________ Item4 |_______Item 3
How can I do it? Do I need to subclass the QSortFilterProxyModel or QIdentityProxyModel or something else? Of course I must not change the data structure in the source model.
I'd subclass QSortFilterProxyModel and re-implement filterAcceptsRow. It's not what QIdentityProxyModel is designed for.