:right-sidebar: True TreeListModel =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: TreeListModel(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gio.ListModel` ``GtkTreeListModel`` is a list model that can create child models on demand. Constructors ------------ .. rst-class:: interim-class .. class:: TreeListModel :no-index: .. classmethod:: new(root: ~gi.repository.Gio.ListModel, passthrough: bool, autoexpand: bool, create_func: ~typing.Callable[[...], ~gi.repository.Gio.ListModel | None], *user_data: ~typing.Any) -> ~gi.repository.Gtk.TreeListModel Creates a new empty ``GtkTreeListModel`` displaying ``root`` with all rows collapsed. :param root: The ``GListModel`` to use as root :param passthrough: :const:`True` to pass through items from the models :param autoexpand: :const:`True` to set the autoexpand property and expand the ``root`` model :param create_func: Function to call to create the ``GListModel`` for the children of an item :param user_data: Data to pass to ``create_func`` Methods ------- .. rst-class:: interim-class .. class:: TreeListModel :no-index: .. method:: get_autoexpand() -> bool Gets whether the model is set to automatically expand new rows that get added. This can be either rows added by changes to the underlying models or via :obj:`~gi.repository.Gtk.TreeListRow.set_expanded`. .. method:: get_child_row(position: int) -> ~gi.repository.Gtk.TreeListRow | None Gets the row item corresponding to the child at index ``position`` for ``self``'s root model. If ``position`` is greater than the number of children in the root model, :const:`None` is returned. Do not confuse this function with :obj:`~gi.repository.Gtk.TreeListModel.get_row`. :param position: position of the child to get .. method:: get_model() -> ~gi.repository.Gio.ListModel Gets the root model that ``self`` was created with. .. method:: get_passthrough() -> bool Gets whether the model is passing through original row items. If this function returns :const:`False`, the ``GListModel`` functions for ``self`` return custom ``GtkTreeListRow`` objects. You need to call :obj:`~gi.repository.Gtk.TreeListRow.get_item` on these objects to get the original item. If :const:`True`, the values of the child models are passed through in their original state. You then need to call :obj:`~gi.repository.Gtk.TreeListModel.get_row` to get the custom ``GtkTreeListRow``'s. .. method:: get_row(position: int) -> ~gi.repository.Gtk.TreeListRow | None Gets the row object for the given row. If ``position`` is greater than the number of items in ``self``, :const:`None` is returned. The row object can be used to expand and collapse rows as well as to inspect its position in the tree. See its documentation for details. This row object is persistent and will refer to the current item as long as the row is present in ``self``, independent of other rows being added or removed. If ``self`` is set to not be passthrough, this function is equivalent to calling :func:`~gi.repository.Gio.Gio.ListModel.get_item`. Do not confuse this function with :obj:`~gi.repository.Gtk.TreeListModel.get_child_row`. :param position: the position of the row to fetch .. method:: set_autoexpand(autoexpand: bool) -> None Sets whether the model should autoexpand. If set to :const:`True`, the model will recursively expand all rows that get added to the model. This can be either rows added by changes to the underlying models or via :obj:`~gi.repository.Gtk.TreeListRow.set_expanded`. :param autoexpand: :const:`True` to make the model autoexpand its rows Properties ---------- .. rst-class:: interim-class .. class:: TreeListModel :no-index: .. attribute:: props.autoexpand :type: bool If all rows should be expanded by default. .. attribute:: props.item_type :type: type The type of items. See :obj:`~gi.repository.Gio.ListModel.get_item_type`. .. versionadded:: 4.8 .. attribute:: props.model :type: ~gi.repository.Gio.ListModel The root model displayed. .. attribute:: props.n_items :type: int The number of items. See :obj:`~gi.repository.Gio.ListModel.get_n_items`. .. versionadded:: 4.8 .. attribute:: props.passthrough :type: bool Gets whether the model is in passthrough mode. If :const:`False`, the ``GListModel`` functions for this object return custom :obj:`~gi.repository.Gtk.TreeListRow` objects. If :const:`True`, the values of the child models are pass through unmodified.