Gtk.GridView

g GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget Gtk.Orientable Gtk.Orientable GObject.GInterface->Gtk.Orientable Gtk.Scrollable Gtk.Scrollable GObject.GInterface->Gtk.Scrollable GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget Gtk.GridView Gtk.GridView Gtk.ListBase Gtk.ListBase Gtk.ListBase->Gtk.GridView Gtk.Orientable->Gtk.ListBase Gtk.Scrollable->Gtk.ListBase Gtk.Widget->Gtk.ListBase

Subclasses:

None

Methods

Inherited:

Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1), Gtk.Orientable (2), Gtk.Scrollable (9)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new (model, factory)

get_enable_rubberband ()

get_factory ()

get_max_columns ()

get_min_columns ()

get_model ()

get_single_click_activate ()

get_tab_behavior ()

scroll_to (pos, flags, scroll)

set_enable_rubberband (enable_rubberband)

set_factory (factory)

set_max_columns (max_columns)

set_min_columns (min_columns)

set_model (model)

set_single_click_activate (single_click_activate)

set_tab_behavior (tab_behavior)

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9), Gtk.Scrollable (1)

Properties

Inherited:

Gtk.Widget (34), Gtk.Accessible (1), Gtk.Orientable (1), Gtk.Scrollable (4)

Name

Type

Flags

Short Description

enable-rubberband

bool

r/w/en

factory

Gtk.ListItemFactory

r/w/en

max-columns

int

r/w/en

min-columns

int

r/w/en

model

Gtk.SelectionModel

r/w/en

single-click-activate

bool

r/w/en

tab-behavior

Gtk.ListTabBehavior

r/w/en

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Name

Short Description

activate

Emitted when a cell has been activated by the user, usually via activating the Gtk.GridView|list.activate-item action.

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Class Details

class Gtk.GridView(**kwargs)
Bases:

Gtk.ListBase

Abstract:

No

Structure:

Gtk.GridViewClass

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 [property`Gtk`.GridView:enable-rubberband].

To learn more about the list widget framework, see the overview.

CSS nodes

`` 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 [property`Gtk`.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 Gtk.AccessibleRole.GRID role, and the items use the Gtk.AccessibleRole.GRID_CELL role.

classmethod new(model, factory)[source]
Parameters:
Returns:

a new GtkGridView using the given model and factory

Return type:

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 ``c grid_view = gtk_grid_view_new (create_model (),

gtk_builder_list_item_factory_new_from_resource (“/resource.ui”));

``

get_enable_rubberband()[source]
Returns:

True if rubberband selection is enabled

Return type:

bool

Returns whether rows can be selected by dragging with the mouse.

get_factory()[source]
Returns:

The factory in use

Return type:

Gtk.ListItemFactory or None

Gets the factory that’s currently used to populate list items.

get_max_columns()[source]
Returns:

The maximum number of columns

Return type:

int

Gets the maximum number of columns that the grid will use.

get_min_columns()[source]
Returns:

The minimum number of columns

Return type:

int

Gets the minimum number of columns that the grid will use.

get_model()[source]
Returns:

The model in use

Return type:

Gtk.SelectionModel or None

Gets the model that’s currently used to read the items displayed.

get_single_click_activate()[source]
Returns:

True if items are activated on single click

Return type:

bool

Returns whether items will be activated on single click and selected on hover.

get_tab_behavior()[source]
Returns:

The behavior of the <kbd>Tab</kbd> key

Return type:

Gtk.ListTabBehavior

Gets the behavior set for the <kbd>Tab</kbd> key.

New in version 4.12.

scroll_to(pos, flags, scroll)[source]
Parameters:

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.

New in version 4.12.

set_enable_rubberband(enable_rubberband)[source]
Parameters:

enable_rubberband (bool) – True to enable rubberband selection

Sets whether selections can be changed by dragging with the mouse.

set_factory(factory)[source]
Parameters:

factory (Gtk.ListItemFactory or None) – the factory to use

Sets the GtkListItemFactory to use for populating list items.

set_max_columns(max_columns)[source]
Parameters:

max_columns (int) – The maximum number of 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 [method`Gtk`.GridView.set_min_columns], that value is used instead.

set_min_columns(min_columns)[source]
Parameters:

min_columns (int) – The minimum number of 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 [method`Gtk`.GridView.set_max_columns], that value is ignored.

set_model(model)[source]
Parameters:

model (Gtk.SelectionModel or None) – the model to use

Sets the model to use.

This must be a [iface`Gtk`.SelectionModel].

set_single_click_activate(single_click_activate)[source]
Parameters:

single_click_activate (bool) – True to activate items on single click

Sets whether items should be activated on single click and selected on hover.

set_tab_behavior(tab_behavior)[source]
Parameters:

tab_behavior (Gtk.ListTabBehavior) – The desired tab behavior

Sets the behavior of the <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keys.

New in version 4.12.

Signal Details

Gtk.GridView.signals.activate(grid_view, position)
Signal Name:

activate

Flags:

RUN_LAST

Parameters:
  • grid_view (Gtk.GridView) – The object which received the signal

  • position (int) – position of item to activate

Emitted when a cell has been activated by the user, usually via activating the Gtk.GridView|list.activate-item action.

This allows for a convenient way to handle activation in a gridview. See [property`Gtk`.ListItem:activatable] for details on how to use this signal.

Property Details

Gtk.GridView.props.enable_rubberband
Name:

enable-rubberband

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Allow rubberband selection.

Gtk.GridView.props.factory
Name:

factory

Type:

Gtk.ListItemFactory

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Factory for populating list items.

Gtk.GridView.props.max_columns
Name:

max-columns

Type:

int

Default Value:

7

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Maximum number of columns per row.

If this number is smaller than [property`Gtk`.GridView:min-columns], that value is used instead.

Gtk.GridView.props.min_columns
Name:

min-columns

Type:

int

Default Value:

1

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Minimum number of columns per row.

Gtk.GridView.props.model
Name:

model

Type:

Gtk.SelectionModel

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Model for the items displayed.

Gtk.GridView.props.single_click_activate
Name:

single-click-activate

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Activate rows on single click and select them on hover.

Gtk.GridView.props.tab_behavior
Name:

tab-behavior

Type:

Gtk.ListTabBehavior

Default Value:

Gtk.ListTabBehavior.ALL

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Behavior of the <kbd>Tab</kbd> key

New in version 4.12.