Skip to content

SubsetFilterProxyModel

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
  1473290745248["itemmodels.SubsetFilterProxyModel"]
  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 --> 1473290745248
  1473299903840 --> 1473299898960
  1473299890176 --> 1473299903840
  1473299815024 --> 1473299890176
  140713234304496 --> 1473299815024
  1473289062816 --> 1473299898960
  1473289061840 --> 1473289062816
  1473289050128 --> 1473289061840
  1473288842240 --> 1473289050128
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: SortFilterProxyModel

A FilterProxyModel to filter based on slices, ranges, indexes or Callables.

Example

proxy = itemmodels.SubsetFilterProxyModel()
proxy.set_source_model(model)
table.set_model(proxy)
table.show()

Note

If you only need filtering based on slices or a single column / row, the SliceFilterProxymodel should be preferred for performance reasons.

Source code in prettyqt\itemmodels\proxies\subsetfilterproxymodel.py
class SubsetFilterProxyModel(core.SortFilterProxyModel):
    """A FilterProxyModel to filter based on slices, ranges, indexes or Callables.

    ### Example

    ```py
    proxy = itemmodels.SubsetFilterProxyModel()
    proxy.set_source_model(model)
    table.set_model(proxy)
    table.show()
    ```

    !!! note
        If you only need filtering based on slices or a single column / row,
        the SliceFilterProxymodel should be preferred for performance reasons.
    """

    ID = "subset"

    def __init__(
        self,
        row_filter: slice | range | int | Container[int] | Callable | None,
        column_filter: slice | range | int | Container[int] | Callable | None,
        **kwargs,
    ):
        self.row_filter = row_filter
        self.column_filter = column_filter
        super().__init__(**kwargs)

    def __repr__(self):
        return get_repr(self, self.row_filter, self.column_filter)

    def filterAcceptsColumn(self, source_column: int, parent: core.ModelIndex) -> bool:
        match self.column_filter:
            case slice() | range():
                return helpers.is_in_slice(self.column_filter, source_column)
            case int():
                return source_column == self.column_filter
            case Container():
                return source_column in self.column_filter
            case Callable():
                return self.column_filter(source_column)
            case None:
                return True
            case _:
                raise ValueError(self.column_filter)

    def filterAcceptsRow(self, source_row: int, parent: core.ModelIndex) -> bool:
        match self.row_filter:
            case slice() | range():
                return helpers.is_in_slice(self.row_filter, source_row)
            case int():
                return source_row == self.row_filter
            case Container():
                return source_row in self.row_filter
            case Callable():
                return self.row_filter(source_row)
            case None:
                return True
            case _:
                raise ValueError(self.row_filter)

⌗ 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