Skip to content

Gtk.SliceListModel

class — extends GObject.Object, Gio.ListModel, SectionModel

A list model that presents a slice of another model.

This is useful when implementing paging by setting the size to the number of elements per page and updating the offset whenever a different page is opened.

GtkSliceListModel passes through sections from the underlying model.

Constructors

new

@classmethod
def new(cls, model: Gio.ListModel | None, offset: int, size: int) -> SliceListModel

Creates a new slice model.

It presents the slice from offset to offset + size of the given model.

Parameters:

  • model — The model to use
  • offset — the offset of the slice
  • size — maximum size of the slice

Methods

get_model

def get_model(self) -> Gio.ListModel | None

Gets the model that is currently being used or None if none.

get_offset

def get_offset(self) -> int

Gets the offset set via SliceListModel.set_offset.

get_size

def get_size(self) -> int

Gets the size set via SliceListModel.set_size.

set_model

def set_model(self, model: Gio.ListModel | None = ...) -> None

Sets the model to show a slice of.

The model's item type must conform to self's item type.

Parameters:

  • model — The model to be sliced

set_offset

def set_offset(self, offset: int) -> None

Sets the offset into the original model for this slice.

If the offset is too large for the sliced model, self will end up empty.

Parameters:

  • offset — the new offset to use

set_size

def set_size(self, size: int) -> None

Sets the maximum size. self will never have more items than size.

It can however have fewer items if the offset is too large or the model sliced from doesn't have enough items.

Parameters:

  • size — the maximum size

Properties

item_type

item_type: type | GObject.Type  # read-only

The type of items. See Gio.ListModel.get_item_type.

model

model: Gio.ListModel  # read/write

Child model to take slice from.

n_items

n_items: int  # read-only

The number of items. See Gio.ListModel.get_n_items.

offset

offset: int  # read/write

Offset of slice.

size

size: int  # read/write

Maximum size of slice.