Skip to content

FilterModel[T]

from slint import FilterModel
python

FilterModel is a Model that provides the rows of a source model for which a filter function returns true.

The FilterModel follows the changes of the source model. Setting a row sets the corresponding row of the source model.

numbers = slint.ListModel([1, 2, 3, 4])
even_numbers = slint.FilterModel(numbers, lambda n: n % 2 == 0)
assert list(even_numbers) == [2, 4]
python

Alternatively, subclass FilterModel and implement filter_row. Call reset when the result of the filter changes for reasons other than a change of the source model:

class Search(slint.FilterModel[str]):
def __init__(self, source: slint.Model[str]) -> None:
self.text = ""
super().__init__(source)
def filter_row(self, row_data: str) -> bool:
return self.text in row_data
search = Search(slint.ListModel(["Hans", "Max", "Roman"]))
search.text = "Max"
search.reset()
python

Bases: _WritableAdapterModel[T]

source_model
filter_row(row_data: T) -> bool

Returns true if row_data, a row of the source model, is a row of this model. Re-implement this method in a sub-class that doesn’t pass a filter function to the constructor.

reset() -> None

Applies the filter to all rows of the source model again. Call this when the result of the filter changes for reasons other than a change of the source model.

unfiltered_row(row: int) -> int

Returns the index of the row of the source model that is row in this model. Raises IndexError if row is out of range.

notify_row_changed(row: int) -> None

Call this method from a sub-class to notify the views that a row has changed.

notify_row_removed(row: int, count: int) -> None

Call this method from a sub-class to notify the views that count rows have been removed starting at row.

notify_row_added(row: int, count: int) -> None

Call this method from a sub-class to notify the views that count rows have been added starting at row.

set_row_data(row: int, value: T) -> None

Sets the row of the source model that corresponds to row. Raises IndexError if row is out of range.

row_count() -> int
row_data(row: int) -> T | None
push_row(value: T) -> None

Add a new row to the model with the provided value. The default implementation calls insert_row with the row count.

remove_row(row: int) -> None

Remove the row at the given index. Raises an exception when the model rejects the modification. The default implementation raises NotImplementedError. A model that supports removing rows should also call notify_row_removed.

insert_row(row: int, value: T) -> None

Insert a new row at the given index. Raises an exception when the model rejects the modification. The default implementation raises NotImplementedError. A model that supports inserting rows should also call notify_row_added.


© 2026 SixtyFPS GmbH