I'm implementing a Qt based tree view, where the view is a QTreeView-based class and the model is a QAbstractItemModel-based class. The tree is supposed to have millions of nodes in it. I'm implementing a filtering mechanism, in which filtered out nodes are just hidden in the tree view. (I don't want to use QSortFilterProxyModel
)
The model's internal data structure looks somewhat like this.
class MyTreeItem
{
...
private:
QList<MyTreeItem *> _children;
bool _isHidden;
};
class MyTreeModel : public QAbstractItemModel
{
...
private:
MyTreeItem * _rootNode;
};
I can determine whether a particular node (MyTreeItem*) should be filtered while the model data structure is being populated. So I want to let the QTreeView know that this item should be hidden while populating the data structure, rather than traversing the entire tree again and hiding rows after populating.
Honestly, I'm in the design stage, so I don't have any real code.
My requirement is, while populating the data structure, I will determine whether the current node should be filtered, and if so, will set the flag _isHidden
. But I'm not sure how to let the view know when to hide the row by calling QTreeView::setRowHidden()
or by some other means.
Please share your thoughts on best way do this. Thanks.