PDA

View Full Version : QTreeView and QSortFilterProxyModel: On-demand model population



elahav
6th February 2009, 16:59
I am using a QTreeView with a model that populates items with children on demand, i.e., only when the item is expanded. To achieve this, the model returns true for hasChildren() before the first expansion, while rowCount() returns 0.
This worked well, until I tried to add a proxy between the model and the view, so that items could be filtered. The proxy returns false for hasChildren(), regardless of the result provided by the underlying model. This means that the expansion icons are not drawn, and the use can not open new items.

Is there another way to force the tree to draw the expansion icons?

Thanks,
--Elad

caduel
6th February 2009, 18:04
subclass the proxy and return true again in hasChildren() ?

elahav
6th February 2009, 18:57
I wish it were that simple...
QSortFilterProxyModel declares this method as non-virtual. That was the first thing I checked.

--Elad

caduel
6th February 2009, 19:54
yeeeeees.... BUT:
it is virtual in the base class. A virtual method stays virtual, that's the point!
(Whether the sub class re-declares the virtual is not important.)

elahav
6th February 2009, 20:18
OK, thanks.
I thought it had to be declared virtual in the immediate base class as well (I can certainly see a benefit to masking virtual functions, in order to ensure certain behaviour, but that's off-topic).

--Elad