ListView


Object Hierarchy:

Object hierarchy for ListView

Description:

[ CCode ( type_id = "gtk_list_view_get_type ()" ) ]
public class ListView : ListBase, Accessible, Buildable, ConstraintTarget, Orientable, Scrollable

GtkListView is a widget to present a view into 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 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 enable_rubberband.

If you need multiple columns with headers, see ColumnView.

To learn more about the list widget framework, see the [overview](ListWidget).

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);

CSS nodes

listview[.separators][.rich-list][.navigation-sidebar][.data-table]
├── row

├── row


╰── [rubberband]
gle CSS node named listview. It may carry the .separators style class, when show_separators property is set. Each child widget uses a single CSS node named row. 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](ListContainers.html#list-styles): .rich-list, .navigation-sidebar or .data-table.

Accessibility

GtkListView uses the LIST role, and the list items use the LIST_ITEM role.


Namespace: Gtk
Package: gtk4

Content:

Properties:

Creation methods:

Methods:

Signals:

Inherited Members:

All known members inherited from class Gtk.Widget
All known members inherited from interface Gtk.Orientable