Gtk.GridView¶
class — extends ListBase, Accessible, Buildable, ConstraintTarget, Orientable, Scrollable
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
GridView.enable-rubberband.
To learn more about the list widget framework, see the overview.
Actions¶
GtkGridView defines a set of built-in actions:
list.activate-itemactivates the item at given position by emitting the theGridView.activatesignal.
CSS nodes¶
GtkGridView uses a single CSS node with name gridview. Each child uses
a single CSS node with name child. If the ListItem.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 AccessibleRole.grid role, and the items
use the AccessibleRole.grid_cell role.
Constructors¶
new¶
@classmethod
def new(cls, model: SelectionModel | None = ..., factory: ListItemFactory | None = ...) -> 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
grid_view = gtk_grid_view_new (create_model (),
gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
Parameters:
model— the model to usefactory— The factory to populate items with
Methods¶
get_enable_rubberband¶
Returns whether rows can be selected by dragging with the mouse.
get_factory¶
Gets the factory that's currently used to populate list items.
get_max_columns¶
Gets the maximum number of columns that the grid will use.
get_min_columns¶
Gets the minimum number of columns that the grid will use.
get_model¶
Gets the model that's currently used to read the items displayed.
get_single_click_activate¶
Returns whether items will be activated on single click and selected on hover.
get_tab_behavior¶
Gets the behavior set for the <kbd>Tab</kbd> key.
scroll_to¶
def scroll_to(self, pos: int, flags: ListScrollFlags | int, scroll: ScrollInfo | 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.
Parameters:
pos— position of the item. Must be less than the number of items in the view.flags— actions to performscroll— details of how to perform the scroll operation orNoneto scroll into view
set_enable_rubberband¶
Sets whether selections can be changed by dragging with the mouse.
Parameters:
enable_rubberband—Trueto enable rubberband selection
set_factory¶
Sets the GtkListItemFactory to use for populating list items.
Parameters:
factory— the factory to use
set_max_columns¶
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
GridView.set_min_columns, that value is used instead.
Parameters:
max_columns— The maximum number of columns
set_min_columns¶
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
GridView.set_max_columns, that value is ignored.
Parameters:
min_columns— The minimum number of columns
set_model¶
Sets the model to use.
This must be a SelectionModel.
Parameters:
model— the model to use
set_single_click_activate¶
Sets whether items should be activated on single click and selected on hover.
Parameters:
single_click_activate—Trueto activate items on single click
set_tab_behavior¶
Sets the behavior of the <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keys.
Parameters:
tab_behavior— The desired tab behavior
Properties¶
enable_rubberband¶
Allow rubberband selection.
factory¶
Factory for populating list items.
The factory must be for configuring ListItem objects.
max_columns¶
Maximum number of columns per row.
If this number is smaller than GridView.min-columns,
that value is used instead.
min_columns¶
Minimum number of columns per row.
model¶
Model for the items displayed.
single_click_activate¶
Activate rows on single click and select them on hover.
tab_behavior¶
Behavior of the <kbd>Tab</kbd> key
Signals¶
activate¶
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 ListItem.activatable for details on how to use
this signal.