I have a QStandardItemModel from which I need to use a subset. The filtering is done not by name but item.data() which is a dict. I can get the text excluded but the items are still populated in the view. How can I exclude the items completely from the view? Is the approach correct?
class WatchlistProxyModel(QSortFilterProxyModel):
def __init__(self, parent=None):
QSortFilterProxyModel.__init__(self, parent)
def data(self, index, role):
if role in (Qt.DisplayRole,):
data = self.sourceModel().itemFromIndex(self.mapToSource(index)).data()
if data is not None:
if data['source'] != '$WATCHLIST$':
return
return QSortFilterProxyModel.data(self, index, role)

Went with the solution suggested by G.M., implementing
data()was not necessary: