Gtk.ListView¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (183), GObject.Object (37), Gtk.Accessible (17), 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. |
Fields¶
- Inherited:
Class Details¶
- class Gtk.ListView(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Presents a large dynamic list of items.
GtkListViewuses 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.
GtkListViewallows 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,intposition,objectunused) {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); ```- Actions
GtkListViewdefines a set of built-in actions:list.activate-itemactivates the item at given position by emitting the [signal`Gtk`.ListView::activate] signal.
- CSS nodes
`` listview[.separators][.rich-list][.navigation-sidebar][.data-table] ├── row[.activatable] │ ├── row[.activatable] │ ┊ ╰── [rubberband] ``
GtkListViewuses a single CSS node namedlistview. It may carry the.separatorsstyle 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.activatablestyle class. For rubberband selection, a node with namerubberbandis 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
GtkListViewuses the [enum`Gtk`.AccessibleRole.list] role, and the list items use the [enum`Gtk`.AccessibleRole.list_item] role.- classmethod new(model, factory)[source]¶
- Parameters:
model (
Gtk.SelectionModelorNone) – the model to usefactory (
Gtk.ListItemFactoryorNone) – The factory to populate items with
- Returns:
a new
GtkListViewusing the given model and factory- Return type:
Creates a new
GtkListViewthat 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_enable_rubberband()[source]¶
- Returns:
true if rubberband selection is enabled
- Return type:
Returns whether rows can be selected by dragging with the mouse.
- 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_show_separators()[source]¶
- Returns:
true if the listview shows separators
- Return type:
Returns whether the listview should show separators between rows.
- get_single_click_activate()[source]¶
- Returns:
true if rows are activated on single click
- Return type:
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 item. Must be less than the number of items in the view.flags (
Gtk.ListScrollFlags) – actions to performscroll (
Gtk.ScrollInfoorNone) – details of how to perform the scroll operation orNoneto 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]¶
- Parameters:
enable_rubberband (
bool) – whether to enable rubberband selection
Sets whether selections can be changed by dragging with the mouse.
- set_factory(factory)[source]¶
- Parameters:
factory (
Gtk.ListItemFactoryorNone) – the factory to use
Sets the
GtkListItemFactoryto use for populating list items.
- set_header_factory(factory)[source]¶
- Parameters:
factory (
Gtk.ListItemFactoryorNone) – the factory to use
Sets the
GtkListItemFactoryto use for populating the [class`Gtk`.ListHeader] objects used in section headers.If this factory is set to
NULL, the list will not show section headers.New in version 4.12.
- set_model(model)[source]¶
- Parameters:
model (
Gtk.SelectionModelorNone) – the model to use
Sets the model to use.
This must be a [iface`Gtk`.SelectionModel] to use.
- set_show_separators(show_separators)[source]¶
- Parameters:
show_separators (
bool) – whether to show separators
Sets whether the listview should show separators between rows.
- set_single_click_activate(single_click_activate)[source]¶
- Parameters:
single_click_activate (
bool) – whether to activate items on single click
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 <kbd>Tab</kbd> key behavior.
This influences how the <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keys move the focus in the listview.
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.
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 [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.
The factory must be for configuring [class`Gtk`.ListItem] objects.
- Gtk.ListView.props.header_factory¶
- Name:
header-factory- Type:
- Default Value:
- Flags:
Factory for creating header widgets.
The factory must be for configuring [class`Gtk`.ListHeader] objects.
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.