Skip to content

ValueFilterProxyModel

Qt Base Class: QSortFilterProxyModel

Signature: QSortFilterProxyModel(self, parent: Optional[PySide6.QtCore.QObject] = None) -> None

Base classes

Name Children Inherits
SortFilterProxyModel
prettyqt.core.sortfilterproxymodel

⋔ Inheritance diagram

graph TD
  1473290730608["itemmodels.ValueFilterProxyModel"]
  1473299898960["core.SortFilterProxyModel"]
  1473299903840["core.AbstractProxyModelMixin"]
  1473299890176["core.AbstractItemModelMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289062816["QtCore.QSortFilterProxyModel"]
  1473289061840["QtCore.QAbstractProxyModel"]
  1473289050128["QtCore.QAbstractItemModel"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473299898960 --> 1473290730608
  1473299903840 --> 1473299898960
  1473299890176 --> 1473299903840
  1473299815024 --> 1473299890176
  140713234304496 --> 1473299815024
  1473289062816 --> 1473299898960
  1473289061840 --> 1473289062816
  1473289050128 --> 1473289061840
  1473288842240 --> 1473289050128
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: SortFilterProxyModel

Proxy model for filtering based on non-str values.

Sometimes it is needed to filter for non-str values, especially when it is required to filter based on a different role than DisplayRole.

Same as the Qt QSortFilterProxyModel, this proxy respects the filterRole and filterKeyColumn properties.

Source code in prettyqt\itemmodels\proxies\valuefilterproxymodel.py
class ValueFilterProxyModel(core.SortFilterProxyModel):
    """Proxy model for filtering based on non-str values.

    Sometimes it is needed to filter for non-str values, especially when it is required
    to filter based on a different role than DisplayRole.

    Same as the Qt QSortFilterProxyModel, this proxy respects the filterRole and
    filterKeyColumn properties.
    """

    ID = "value_filter"

    def __init__(self, filter_value=None, **kwargs):
        self._filter_value = filter_value
        super().__init__(**kwargs)

    def __repr__(self):
        return get_repr(self, self._filter_value)

    def filterAcceptsRow(self, source_row: int, parent: core.ModelIndex) -> bool:
        if self._filter_value is None:
            return True
        column = self.filterKeyColumn()
        role = self.filterRole()
        source_model = self.sourceModel()
        idx = source_model.index(source_row, column, parent)
        value = source_model.data(idx, role)
        return value == self._filter_value

    def set_filter_value(self, value):
        """Set the filter value."""
        self._filter_value = value
        self.invalidateRowsFilter()

    def get_filter_value(self):
        """Get the filter value."""
        return self._filter_value

    filter_value = core.Property(
        object,
        get_filter_value,
        set_filter_value,
        user=True,
        doc="Value to use for filtering",
    )

get_filter_value()

Get the filter value.

Source code in prettyqt\itemmodels\proxies\valuefilterproxymodel.py
def get_filter_value(self):
    """Get the filter value."""
    return self._filter_value

set_filter_value(value)

Set the filter value.

Source code in prettyqt\itemmodels\proxies\valuefilterproxymodel.py
def set_filter_value(self, value):
    """Set the filter value."""
    self._filter_value = value
    self.invalidateRowsFilter()

⌗ Property table

Qt Property Type Doc
objectName QString
sourceModel QAbstractItemModel
filterRegularExpression QRegularExpression
filterKeyColumn int
dynamicSortFilter bool
filterCaseSensitivity Qt::CaseSensitivity
sortCaseSensitivity Qt::CaseSensitivity
isSortLocaleAware bool
sortRole int
filterRole int
recursiveFilteringEnabled bool
autoAcceptChildRows bool
filterMode QString Mode to use for filtering
filter_value PySide::PyObjectWrapper Value to use for filtering