I have my own class that inherits from QAbstractItemModel which has tree structure.
I use a couple of views, that display filtered data of this model, using classes derived from QSortFilterProxyModel.
My model structure looks like this:
root
|
-- A
| |-A1
| |-A2
| |-A3
|
-- B
| |-B1
| |-B2
|
... and so on...
Where A, B .... are "main rows" (children of the root), and A1, A2, ... B1, B2... are "children rows" - node rows appended to "main rows".
Now, what I need to do is a QTableView that displays "children rows" only:
A1
A2
A3
B1
B2
But filtering methods I found in QSortFilterProxyModel (filterAcceptsRow, filterAcceptsColumn), operates on main rows only...
How can I do it?
(I found very similar question, but it is still unanswered: QTableView to display only leaves of a tree model implemented with QAbstractItemModel)
I see 3 possible solutions for this problem. First two solutions offered Dmitry Sazonov in his comment for this question:
QAbstractProxyModel
.QAbstractItemModel
and create another model for such view.The third possible solution is little trick with reimplementation of
QStyledItemDelegate
for view. I make small example for such solution. I hope, it will be useful: