Skip to content

MapModel[T, U]

from slint import MapModel
python

MapModel is a read-only Model that provides the rows of a source model, each passed through a map function.

The MapModel follows the changes of the source model.

names = slint.ListModel([("Hans", "Emil"), ("Max", "Mustermann")])
full_names = slint.MapModel(names, lambda name: f"{name[1]}, {name[0]}")
assert full_names[0] == "Emil, Hans"
python

Alternatively, subclass MapModel and implement map_row:

class FullNames(slint.MapModel[tuple[str, str], str]):
def map_row(self, row_data: tuple[str, str]) -> str:
return f"{row_data[1]}, {row_data[0]}"
full_names = FullNames(names)
python

Bases: _AdapterModel[U]

source_model
map_row(row_data: T) -> U

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

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

Call this method on mutable models to change the data for the given row. The UI will also call this method when modifying a model’s data. Re-implement this method in a sub-class to handle the change.

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