I have a working tree model derived from QAbstractItemModel and I wish to filter it using a QSortFilterProxyModel subclass to display only children nodes of certain criteria. For example I have the following tree:

A
- B
-- C1
-- C1
-- C1
--- C2
- D
- E

I want to filter this tree with the condition that the node has name == C1 and display only the nodes with C1 and their children like this:

C1
C1
C1
- C2

I already have a subclass with filterAcceptsRow() re-implemented that can partially do what I want but it will still show the parent and grandparent of C1 nodes:

A
- B
-- C1
-- C1
-- C1
--- C2

I think this is because for children nodes to even be considered, their parent has to pass the filterAcceptsRow() test, am I right? How can I write filterAcceptRows such that it can do what I have described?