QSortFilterProxyModel: Proper use of beginFilterChange()/endFilterChange()?
-
When header data changes in my source model, I want my
QSortFilterProxyModelto invalidate its columns filter.I used to do this with:
self.sourceModel().headerChanged.connect(self.invalidateColumnsFilter)However, the docs have now listed
invalidateColumnsFilteras deprecated and suggest to usebeginFilterChange()andendFilterChange(Direction)instead. That's cool, but I feel a little weird about it sinceQAbstractItemModeldoesn't have "dataAboutToChange" or "headerDataAboutToChange"-style signals to link up the beginFilter/endFilter stuff; it just has dataChanged / headerDataChanged.So am I okay to connect headerDataChanged() to a method in my proxy model that then calls both the begin/endFilterChange() methods? This feels out-of-order.
self.sourceModel().headerDataChanged.connect(self.binColumnDataChanged) @QtCore.Slot(QtCore.Qt.Orientation, int, int) def binColumnDataChanged(self, orientation:QtCore.Qt.Orientation, first:int, last:int): self.beginFilterChange() self.endFilterChange(QtCore.QSortFilterProxyModel.Direction.Columns)