c++qtviewmodelqabstractitemmodelqsortfilterproxymodel

"group by" proxy model


I have tree model with theoretically infinite depth and some property "Group".

original view

In addition to standard view, I need to show this model (and keep it in sync) in such way that each group becomes a virtual parent for all items with the same property value.

enter image description here

What is the best way to achieve this with Qt's model/view architecture?

I had solved similar problem not a long time ago via inserting additional virtual "groups" on adding/removing items to/from the model, but this method proved not to be very flexible so I'm looking for better solution.

Ideally, I see this implemented via QSortProxyFilter model as for now.


Solution

  • Depending on what you want as a final result :