:right-sidebar: True GridView =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: GridView(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gtk.ListBase`, :class:`~gi.repository.Gtk.Widget`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gtk.Accessible`, :class:`~gi.repository.Gtk.Buildable`, :class:`~gi.repository.Gtk.ConstraintTarget`, :class:`~gi.repository.Gtk.Orientable`, :class:`~gi.repository.Gtk.Scrollable` ``GtkGridView`` presents a large dynamic grid of items. ``GtkGridView`` uses its factory to generate one child widget for each visible item and shows them in a grid. The orientation of the grid view determines if the grid reflows vertically or horizontally. ``GtkGridView`` allows the user to select items according to the selection characteristics of the model. For models that allow multiple selected items, it is possible to turn on *rubberband selection*, using :obj:`~gi.repository.Gtk.GridView.props.enable_rubberband`. To learn more about the list widget framework, see the `overview `_. CSS nodes --------- .. code-block:: :dedent: gridview ├── child[.activatable] │ ├── child[.activatable] │ ┊ ╰── [rubberband] ``GtkGridView`` uses a single CSS node with name ``gridview``. Each child uses a single CSS node with name ``child``. If the :obj:`~gi.repository.Gtk.ListItem.props.activatable` property is set, the corresponding row will have the ``.activatable`` style class. For rubberband selection, a subnode with name ``rubberband`` is used. Accessibility ------------- ``GtkGridView`` uses the :const:`~gi.repository.Gtk.AccessibleRole.GRID` role, and the items use the :const:`~gi.repository.Gtk.AccessibleRole.GRID_CELL` role. Constructors ------------ .. rst-class:: interim-class .. class:: GridView :no-index: .. classmethod:: new(model: ~gi.repository.Gtk.SelectionModel | None = None, factory: ~gi.repository.Gtk.ListItemFactory | None = None) -> ~gi.repository.Gtk.Widget Creates a new ``GtkGridView`` that uses the given ``factory`` for mapping items to widgets. The function takes ownership of the arguments, so you can write code like .. code-block:: :dedent: grid_view = gtk_grid_view_new (create_model (), gtk_builder_list_item_factory_new_from_resource ("/resource.ui")); :param model: the model to use :param factory: The factory to populate items with Methods ------- .. rst-class:: interim-class .. class:: GridView :no-index: .. method:: get_enable_rubberband() -> bool Returns whether rows can be selected by dragging with the mouse. .. method:: get_factory() -> ~gi.repository.Gtk.ListItemFactory | None Gets the factory that's currently used to populate list items. .. method:: get_max_columns() -> int Gets the maximum number of columns that the grid will use. .. method:: get_min_columns() -> int Gets the minimum number of columns that the grid will use. .. method:: get_model() -> ~gi.repository.Gtk.SelectionModel | None Gets the model that's currently used to read the items displayed. .. method:: get_single_click_activate() -> bool Returns whether items will be activated on single click and selected on hover. .. method:: get_tab_behavior() -> ~gi.repository.Gtk.ListTabBehavior Gets the behavior set for the :kbd:`Tab` key. .. versionadded:: 4.12 .. method:: scroll_to(pos: int, flags: ~gi.repository.Gtk.ListScrollFlags, scroll: ~gi.repository.Gtk.ScrollInfo | None = None) -> None Scrolls to the item at the given position and performs the actions specified in ``flags``. This function works no matter if the gridview is shown or focused. If it isn't, then the changes will take effect once that happens. .. versionadded:: 4.12 :param pos: position of the item :param flags: actions to perform :param scroll: details of how to perform the scroll operation or :const:`None` to scroll into view .. method:: set_enable_rubberband(enable_rubberband: bool) -> None Sets whether selections can be changed by dragging with the mouse. :param enable_rubberband: :const:`True` to enable rubberband selection .. method:: set_factory(factory: ~gi.repository.Gtk.ListItemFactory | None = None) -> None Sets the ``GtkListItemFactory`` to use for populating list items. :param factory: the factory to use .. method:: set_max_columns(max_columns: int) -> None Sets the maximum number of columns to use. This number must be at least 1. If ``max_columns`` is smaller than the minimum set via :obj:`~gi.repository.Gtk.GridView.set_min_columns`, that value is used instead. :param max_columns: The maximum number of columns .. method:: set_min_columns(min_columns: int) -> None Sets the minimum number of columns to use. This number must be at least 1. If ``min_columns`` is smaller than the minimum set via :obj:`~gi.repository.Gtk.GridView.set_max_columns`, that value is ignored. :param min_columns: The minimum number of columns .. method:: set_model(model: ~gi.repository.Gtk.SelectionModel | None = None) -> None Sets the model to use. This must be a :obj:`~gi.repository.Gtk.SelectionModel`. :param model: the model to use .. method:: set_single_click_activate(single_click_activate: bool) -> None Sets whether items should be activated on single click and selected on hover. :param single_click_activate: :const:`True` to activate items on single click .. method:: set_tab_behavior(tab_behavior: ~gi.repository.Gtk.ListTabBehavior) -> None Sets the behavior of the :kbd:`Tab` and :kbd:`Shift`+:kbd:`Tab` keys. .. versionadded:: 4.12 :param tab_behavior: The desired tab behavior Properties ---------- .. rst-class:: interim-class .. class:: GridView :no-index: .. attribute:: props.enable_rubberband :type: bool Allow rubberband selection. .. attribute:: props.factory :type: ~gi.repository.Gtk.ListItemFactory Factory for populating list items. .. attribute:: props.max_columns :type: int Maximum number of columns per row. If this number is smaller than :obj:`~gi.repository.Gtk.GridView.props.min_columns`, that value is used instead. .. attribute:: props.min_columns :type: int Minimum number of columns per row. .. attribute:: props.model :type: ~gi.repository.Gtk.SelectionModel Model for the items displayed. .. attribute:: props.single_click_activate :type: bool Activate rows on single click and select them on hover. .. attribute:: props.tab_behavior :type: ~gi.repository.Gtk.ListTabBehavior Behavior of the :kbd:`Tab` key .. versionadded:: 4.12 Signals ------- .. rst-class:: interim-class .. class:: GridView.signals :no-index: .. method:: activate(position: int) -> None Emitted when a cell has been activated by the user, usually via activating the GtkGridView|list.activate-item action. This allows for a convenient way to handle activation in a gridview. See :obj:`~gi.repository.Gtk.ListItem.props.activatable` for details on how to use this signal. :param position: position of item to activate