1.116 <GtkListView>

Class: <GtkListView>

It derives from <GtkListBase>.

Presents a large dynamic list of items.

<GtkListView> uses its factory to generate one row widget for each visible item and shows them in a linear display, either vertically or horizontally.

The list-view:show-separators property offers a simple way to display separators between the rows.

<GtkListView> 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 list-view:enable-rubberband.

If you need multiple columns with headers, see <GtkColumnView>.

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

An example of using <GtkListView>:

static void
setup_listitem_cb (GtkListItemFactory *factory,
                   GtkListItem        *list_item)
{
  GtkWidget *image;

  image = gtk_image_new ();
  gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
  gtk_list_item_set_child (list_item, image);
}

static void
bind_listitem_cb (GtkListItemFactory *factory,
                  GtkListItem        *list_item)
{
  GtkWidget *image;
  GAppInfo *app_info;

  image = gtk_list_item_get_child (list_item);
  app_info = gtk_list_item_get_item (list_item);
  gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info));
}

static void
activate_cb (GtkListView  *list,
             guint         position,
             gpointer      unused)
{
  GAppInfo *app_info;

  app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position);
  g_app_info_launch (app_info, NULL, NULL, NULL);
  g_object_unref (app_info);
}

...

  model = create_application_list ();

  factory = gtk_signal_list_item_factory_new ();
  g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
  g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);

  list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);

  g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);

  gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);

Actions

<GtkListView> defines a set of built-in actions:

  • list.activate-item activates the item at given position by emitting the list-view:activate signal.

CSS nodes

listview[.separators][.rich-list][.navigation-sidebar][.data-table]
├── row[.activatable]
│
├── row[.activatable]
│
┊
╰── [rubberband]

<GtkListView> uses a single CSS node named listview. It may carry the .separators style class, when list-view:show-separators property is set. Each child widget uses a single CSS node named row. If the list-item:activatable property is set, the corresponding row will have the .activatable style class. For rubberband selection, a node with name rubberband is used.

The main listview node may also carry style classes to select the style of list presentation: .rich-list, .navigation-sidebar or .data-table.

Accessibility

<GtkListView> uses the Gtk.AccessibleRole.list role, and the list items use the Gtk.AccessibleRole.list_item role.

Properties

Property: list-view:enable-rubberband self

Allow rubberband selection.

Its value is a boolean.

Set it with (set! (list-view:enable-rubberband self) value).

Property: list-view:factory self

Factory for populating list items.

The factory must be for configuring <GtkListItem> objects.

Its value is a <GtkListItemFactory>, or #f.

Set it with (set! (list-view:factory self) value).

Property: list-view:header-factory self

Factory for creating header widgets.

The factory must be for configuring <GtkListHeader> objects.

Its value is a <GtkListItemFactory>, or #f.

Set it with (set! (list-view:header-factory self) value).

Property: list-view:model self

Model for the items displayed.

Its value is a <GtkSelectionModel>, or #f.

Set it with (set! (list-view:model self) value).

Property: list-view:show-separators self

Show separators between rows.

Its value is a boolean.

Set it with (set! (list-view:show-separators self) value).

Property: list-view:single-click-activate self

Activate rows on single click and select them on hover.

Its value is a boolean.

Set it with (set! (list-view:single-click-activate self) value).

Property: list-view:tab-behavior self

Behavior of the Tab key

Its value is a <GtkListTabBehavior> (or, to set it, one of its symbols).

Set it with (set! (list-view:tab-behavior self) value).

Procedures

Method: list-view:get-enable-rubberband? self ⇒ %return
Method: get-enable-rubberband? self ⇒ %return

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

self

Passed: a <GtkListView>.

a listview

%return

Returned: a boolean.

true if rubberband selection is enabled

Method: list-view:get-factory self ⇒ %return
Method: get-factory self ⇒ %return

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

self

Passed: a <GtkListView>.

a listview

%return

Returned: a <GtkListItemFactory>, or #f.

The factory in use

Method: list-view:get-header-factory self ⇒ %return
Method: get-header-factory self ⇒ %return

Gets the factory that’s currently used to populate section headers.

self

Passed: a <GtkListView>.

a listview

%return

Returned: a <GtkListItemFactory>, or #f.

The factory in use

Method: list-view:get-model self ⇒ %return
Method: get-model self ⇒ %return

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

self

Passed: a <GtkListView>.

a listview

%return

Returned: a <GtkSelectionModel>, or #f.

The model in use

Method: list-view:get-show-separators? self ⇒ %return
Method: get-show-separators? self ⇒ %return

Returns whether the listview should show separators between rows.

self

Passed: a <GtkListView>.

a listview

%return

Returned: a boolean.

true if the listview shows separators

Method: list-view:get-single-click-activate? self ⇒ %return
Method: get-single-click-activate? self ⇒ %return

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

self

Passed: a <GtkListView>.

a listview

%return

Returned: a boolean.

true if rows are activated on single click

Method: list-view:get-tab-behavior self ⇒ %return
Method: get-tab-behavior self ⇒ %return

Gets the behavior set for the Tab key.

self

Passed: a <GtkListView>.

a listview

%return

Returned: a <GtkListTabBehavior>.

The behavior of the Tab key

Procedure: list-view:new [model] [factory] ⇒ %return

Creates a new <GtkListView> that uses the given factory for mapping items to widgets.

The function takes ownership of the arguments, so you can write code like

list_view = gtk_list_view_new (create_model (),
  gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
model

Passed, or left out: a <GtkSelectionModel>, or #f.

the model to use

factory

Passed, or left out: a <GtkListItemFactory>, or #f.

The factory to populate items with

%return

Returned: a <GtkWidget>.

a new <GtkListView> using the given model and factory

Method: list-view:scroll-to self pos flags [scroll]
Method: scroll-to self pos flags [scroll]

Scrolls to the item at the given position and performs the actions specified in flags.

This function works no matter if the listview is shown or focused. If it isn’t, then the changes will take effect once that happens.

self

Passed: a <GtkListView>.

a listview

pos

Passed: an unsigned 32-bit integer.

position of the item. Must be less than the number of items in the view.

flags

Passed: a <GtkListScrollFlags>, or a list of its symbols, or one of them.

actions to perform

scroll

Passed, or left out: a <GtkScrollInfo>, or #f.

details of how to perform the scroll operation or #f to scroll into view

Method: list-view:set-enable-rubberband self enable-rubberband
Method: set-enable-rubberband self enable-rubberband

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

self

Passed: a <GtkListView>.

a listview

enable-rubberband

Passed: a boolean.

whether to enable rubberband selection

Method: list-view:set-factory self [factory]
Method: set-factory self [factory]

Sets the <GtkListItemFactory> to use for populating list items.

self

Passed: a <GtkListView>.

a listview

factory

Passed, or left out: a <GtkListItemFactory>, or #f.

the factory to use

Method: list-view:set-header-factory self [factory]
Method: set-header-factory self [factory]

Sets the <GtkListItemFactory> to use for populating the <GtkListHeader> objects used in section headers.

If this factory is set to NULL, the list will not show section headers.

self

Passed: a <GtkListView>.

a listview

factory

Passed, or left out: a <GtkListItemFactory>, or #f.

the factory to use

Method: list-view:set-model self [model]
Method: set-model self [model]

Sets the model to use.

This must be a <GtkSelectionModel> to use.

self

Passed: a <GtkListView>.

a listview

model

Passed, or left out: a <GtkSelectionModel>, or #f.

the model to use

Method: list-view:set-show-separators self show-separators
Method: set-show-separators self show-separators

Sets whether the listview should show separators between rows.

self

Passed: a <GtkListView>.

a listview

show-separators

Passed: a boolean.

whether to show separators

Method: list-view:set-single-click-activate self single-click-activate
Method: set-single-click-activate self single-click-activate

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

self

Passed: a <GtkListView>.

a listview

single-click-activate

Passed: a boolean.

whether to activate items on single click

Method: list-view:set-tab-behavior self tab-behavior
Method: set-tab-behavior self tab-behavior

Sets the Tab key behavior.

This influences how the Tab and Shift+Tab keys move the focus in the listview.

self

Passed: a <GtkListView>.

a listview

tab-behavior

Passed: a <GtkListTabBehavior>, or one of its symbols.

The desired tab behavior

Signals

Signal: list-view:activate

Connect a handler with (connect object list-view:activate handler). It is called as (handler self position).

Emitted when a row has been activated by the user.

Activation usually happens via the list.activate-item action of the <GtkListView>.

This allows for a convenient way to handle activation in a listview. See list-item:set-activatable for details on how to use this signal.

self

Passed: a <GtkListView>.

position

Passed: an unsigned 32-bit integer.

position of item to activate