:right-sidebar: True ListItem =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: ListItem(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Gtk.ColumnViewCell` ``GtkListItem`` is used by list widgets to represent items in a :obj:`~gi.repository.Gio.ListModel`. ``GtkListItem`` objects are managed by the list widget (with its factory) and cannot be created by applications, but they need to be populated by application code. This is done by calling :obj:`~gi.repository.Gtk.ListItem.set_child`. ``GtkListItem`` objects exist in 2 stages: 1. The unbound stage where the listitem is not currently connected to an item in the list. In that case, the :obj:`~gi.repository.Gtk.ListItem.props.item` property is set to :const:`None`. 2. The bound stage where the listitem references an item from the list. The :obj:`~gi.repository.Gtk.ListItem.props.item` property is not :const:`None`. Methods ------- .. rst-class:: interim-class .. class:: ListItem :no-index: .. method:: get_accessible_description() -> str Gets the accessible description of ``self``. .. versionadded:: 4.12 .. method:: get_accessible_label() -> str Gets the accessible label of ``self``. .. versionadded:: 4.12 .. method:: get_activatable() -> bool Checks if a list item has been set to be activatable via :func:`~gi.repository.Gtk.ListItem.set_activatable`. .. method:: get_child() -> ~gi.repository.Gtk.Widget | None Gets the child previously set via :func:`~gi.repository.Gtk.ListItem.set_child` or :const:`None` if none was set. .. method:: get_focusable() -> bool Checks if a list item has been set to be focusable via :func:`~gi.repository.Gtk.ListItem.set_focusable`. .. versionadded:: 4.12 .. method:: get_item() -> ~gi.repository.GObject.Object | None Gets the model item that associated with ``self``. If ``self`` is unbound, this function returns :const:`None`. .. method:: get_position() -> int Gets the position in the model that ``self`` currently displays. If ``self`` is unbound, :const:`~gi.repository.Gtk.INVALID_LIST_POSITION` is returned. .. method:: get_selectable() -> bool Checks if a list item has been set to be selectable via :func:`~gi.repository.Gtk.ListItem.set_selectable`. Do not confuse this function with :obj:`~gi.repository.Gtk.ListItem.get_selected`. .. method:: get_selected() -> bool Checks if the item is displayed as selected. The selected state is maintained by the liste widget and its model and cannot be set otherwise. .. method:: set_accessible_description(description: str) -> None Sets the accessible description for the list item, which may be used by e.g. screen readers. .. versionadded:: 4.12 :param description: the description .. method:: set_accessible_label(label: str) -> None Sets the accessible label for the list item, which may be used by e.g. screen readers. .. versionadded:: 4.12 :param label: the label .. method:: set_activatable(activatable: bool) -> None Sets ``self`` to be activatable. If an item is activatable, double-clicking on the item, using the Return key or calling :func:`~gi.repository.Gtk.Widget.activate` will activate the item. Activating instructs the containing view to handle activation. ``GtkListView`` for example will be emitting the :obj:`~gi.repository.Gtk.ListView.signals.activate` signal. By default, list items are activatable. :param activatable: if the item should be activatable .. method:: set_child(child: ~gi.repository.Gtk.Widget | None = None) -> None Sets the child to be used for this listitem. This function is typically called by applications when setting up a listitem so that the widget can be reused when binding it multiple times. :param child: The list item's child or :const:`None` to unset .. method:: set_focusable(focusable: bool) -> None Sets ``self`` to be focusable. If an item is focusable, it can be focused using the keyboard. This works similar to :obj:`~gi.repository.Gtk.Widget.set_focusable`. Note that if items are not focusable, the keyboard cannot be used to activate them and selecting only works if one of the listitem's children is focusable. By default, list items are focusable. .. versionadded:: 4.12 :param focusable: if the item should be focusable .. method:: set_selectable(selectable: bool) -> None Sets ``self`` to be selectable. If an item is selectable, clicking on the item or using the keyboard will try to select or unselect the item. If this succeeds is up to the model to determine, as it is managing the selected state. Note that this means that making an item non-selectable has no influence on the selected state at all. A non-selectable item may still be selected. By default, list items are selectable. When rebinding them to a new item, they will also be reset to be selectable by GTK. :param selectable: if the item should be selectable Properties ---------- .. rst-class:: interim-class .. class:: ListItem :no-index: .. attribute:: props.accessible_description :type: str The accessible description to set on the list item. .. versionadded:: 4.12 .. attribute:: props.accessible_label :type: str The accessible label to set on the list item. .. versionadded:: 4.12 .. attribute:: props.activatable :type: bool If the item can be activated by the user. .. attribute:: props.child :type: ~gi.repository.Gtk.Widget Widget used for display. .. attribute:: props.focusable :type: bool If the item can be focused with the keyboard. .. versionadded:: 4.12 .. attribute:: props.item :type: ~gi.repository.GObject.Object Displayed item. .. attribute:: props.position :type: int Position of the item. .. attribute:: props.selectable :type: bool If the item can be selected by the user. .. attribute:: props.selected :type: bool If the item is currently selected.