Gtk.ListView¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1), Gtk.Orientable (2), Gtk.Scrollable (9)
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Emitted when a row has been activated by the user, usually via activating the |
Fields¶
- Inherited:
Class Details¶
- class Gtk.ListView(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
GtkListView
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 [property`Gtk`.ListView: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 [property`Gtk`.ListView:enable-rubberband].If you need multiple columns with headers, see [class`Gtk`.ColumnView].
To learn more about the list widget framework, see the overview.
An example of using
GtkListView
: ```c static void setup_listitem_cb (Gtk.ListItemFactory
*factory,Gtk.ListItem
*list_item) {Gtk.Widget
*image;image =
Gtk.Image.new
();Gtk.Image.set_icon_size
(GTK_IMAGE (image),Gtk.IconSize.LARGE
);Gtk.ListItem.set_child
(list_item, image); }static void bind_listitem_cb (
Gtk.ListItemFactory
*factory,Gtk.ListItem
*list_item) {Gtk.Widget
*image;Gio.AppInfo
*app_info;image =
Gtk.ListItem.get_child
(list_item); app_info =Gtk.ListItem.get_item
(list_item);Gtk.Image.set_from_gicon
(GTK_IMAGE (image),Gio.AppInfo.get_icon
(app_info)); }static void activate_cb (
Gtk.ListView
*list,int
position,object
unused) {Gio.AppInfo
*app_info;app_info =
Gio.ListModel.get_item
(G_LIST_MODEL (Gtk.ListView.get_model
(list)), position);Gio.AppInfo.launch
(app_info,None
,None
,None
);GObject.Object.unref
(app_info); }…
model = create_application_list ();
factory =
Gtk.SignalListItemFactory.new
(); g_signal_connect (factory, “setup”, G_CALLBACK (setup_listitem_cb),None
); g_signal_connect (factory, “bind”, G_CALLBACK (bind_listitem_cb),None
);list =
Gtk.ListView.new
(GTK_SELECTION_MODEL (Gtk.SingleSelection.new
(model)), factory);g_signal_connect (list, “activate”, G_CALLBACK (activate_cb),
None
);Gtk.ScrolledWindow.set_child
(GTK_SCROLLED_WINDOW (sw), list); ```- CSS nodes
`` listview[.separators][.rich-list][.navigation-sidebar][.data-table] ├── row[.activatable] │ ├── row[.activatable] │ ┊ ╰── [rubberband] ``
GtkListView
uses a single CSS node namedlistview
. It may carry the.separators
style class, when [property`Gtk`.ListView:show-separators] property is set. Each child widget uses a single CSS node namedrow
. If the [property`Gtk`.ListItem:activatable] property is set, the corresponding row will have the.activatable
style class. For rubberband selection, a node with namerubberband
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 theGtk.AccessibleRole.LIST
role, and the list items use theGtk.AccessibleRole.LIST_ITEM
role.- classmethod new(model, factory)[source]¶
- Parameters:
model (
Gtk.SelectionModel
orNone
) – the model to usefactory (
Gtk.ListItemFactory
orNone
) – The factory to populate items with
- Returns:
a new
GtkListView
using the given model and factory- Return type:
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 ``c list_view = gtk_list_view_new (create_model (),
gtk_builder_list_item_factory_new_from_resource (“/resource.ui”));
- get_factory()[source]¶
- Returns:
The factory in use
- Return type:
Gets the factory that’s currently used to populate list items.
- get_header_factory()[source]¶
- Returns:
The factory in use
- Return type:
Gets the factory that’s currently used to populate section headers.
New in version 4.12.
- get_model()[source]¶
- Returns:
The model in use
- Return type:
Gets the model that’s currently used to read the items displayed.
- get_single_click_activate()[source]¶
-
Returns whether rows 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:
Gets the behavior set for the <kbd>Tab</kbd> key.
New in version 4.12.
- scroll_to(pos, flags, scroll)[source]¶
- Parameters:
pos (
int
) – position of the itemflags (
Gtk.ListScrollFlags
) – actions to performscroll (
Gtk.ScrollInfo
orNone
) – details of how to perform the scroll operation orNone
to scroll into view
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.
New in version 4.12.
- set_enable_rubberband(enable_rubberband)[source]¶
-
Sets whether selections can be changed by dragging with the mouse.
- set_factory(factory)[source]¶
- Parameters:
factory (
Gtk.ListItemFactory
orNone
) – the factory to use
Sets the
GtkListItemFactory
to use for populating list items.
- set_header_factory(factory)[source]¶
- Parameters:
factory (
Gtk.ListItemFactory
orNone
) – the factory to use
Sets the
GtkListItemFactory
to use for populating the [class`Gtk`.ListHeader] objects used in section headers.If this factory is set to
None
, the list will not show section headers.New in version 4.12.
- set_model(model)[source]¶
- Parameters:
model (
Gtk.SelectionModel
orNone
) – the model to use
Sets the model to use.
This must be a [iface`Gtk`.SelectionModel] to use.
- set_show_separators(show_separators)[source]¶
-
Sets whether the list box should show separators between rows.
- set_single_click_activate(single_click_activate)[source]¶
-
Sets whether rows 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.ListView.signals.activate(list_view, position)¶
- Signal Name:
activate
- Flags:
- Parameters:
list_view (
Gtk.ListView
) – The object which received the signalposition (
int
) – position of item to activate
Emitted when a row has been activated by the user, usually via activating the
Gtk.ListView
|list.activate-item action.This allows for a convenient way to handle activation in a listview. See [method`Gtk`.ListItem.set_activatable] for details on how to use this signal.
Property Details¶
- Gtk.ListView.props.enable_rubberband¶
- Name:
enable-rubberband
- Type:
- Default Value:
- Flags:
Allow rubberband selection.
- Gtk.ListView.props.factory¶
- Name:
factory
- Type:
- Default Value:
- Flags:
Factory for populating list items.
- Gtk.ListView.props.header_factory¶
- Name:
header-factory
- Type:
- Default Value:
- Flags:
Factory for creating header widgets.
New in version 4.12.
- Gtk.ListView.props.model¶
- Name:
model
- Type:
- Default Value:
- Flags:
Model for the items displayed.
- Gtk.ListView.props.show_separators¶
- Name:
show-separators
- Type:
- Default Value:
- Flags:
Show separators between rows.
- Gtk.ListView.props.single_click_activate¶
- Name:
single-click-activate
- Type:
- Default Value:
- Flags:
Activate rows on single click and select them on hover.
- Gtk.ListView.props.tab_behavior¶
- Name:
tab-behavior
- Type:
- Default Value:
- Flags:
Behavior of the <kbd>Tab</kbd> key
New in version 4.12.