How can I autoexpand an item in a QTreeView when it is filtered by QSortFilterProxyModel?
I have a normal QTreeView, a custom QAbstractItemModel and a custom QSortFilterProxyModel.
I've reimplemented QSortFilterProxyModel::filterAcceptsRow to filter items from my model in the way I want, however now I want those filtered items to be expanded in the treeview.
The obvious solution was to emit a signal from QSortFilterProxyModel::filterAcceptsRow() when an accepted item was found, then connect that signal to the QTreeView::expand().
However, QSortFilterProxyModel::filterAcceptsRow() is const, so I cannot emit a signal from inside that method. QSortFilterProxyModel doesn't have any other signals that would aid me.. and I am beginning to think I will have to subc开发者_运维百科lass QTreeView, which I'd rather not do (less code == better).
So, is there any way to autoexpand those items that the filtermodel accepts?
QTreeView has a "expandAll" slot, which could be called after you set the model. I would think that this should do what you want.
精彩评论