Skip to content

Gtk.ColumnView

class — extends Widget, Accessible, Buildable, ConstraintTarget, Scrollable

Presents a large dynamic list of items using multiple columns with headers.

GtkColumnView uses the factories of its columns to generate a cell widget for each column, for each visible item and displays them together as the row for this item.

The ColumnView.show-row-separators and ColumnView.show-column-separators properties offer a simple way to display separators between the rows or columns.

GtkColumnView 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 ColumnView.enable-rubberband.

The column view supports sorting that can be customized by the user by clicking on column headers. To set this up, the GtkSorter returned by ColumnView.get_sorter must be attached to a sort model for the data that the view is showing, and the columns must have sorters attached to them by calling ColumnViewColumn.set_sorter. The initial sort order can be set with ColumnView.sort_by_column.

The column view also supports interactive resizing and reordering of columns, via Drag-and-Drop of the column headers. This can be enabled or disabled with the ColumnView.reorderable and ColumnViewColumn.resizable properties.

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

CSS nodes

columnview[.column-separators][.rich-list][.navigation-sidebar][.data-table]
├── header
│   ├── <column header>
┊   ┊
│   ╰── <column header>
├── listview
╰── [rubberband]

GtkColumnView uses a single CSS node named columnview. It may carry the .column-separators style class, when ColumnView.show-column-separators property is set. Header widgets appear below a node with name header. The rows are contained in a GtkListView widget, so there is a listview node with the same structure as for a standalone GtkListView widget. If ColumnView.show-row-separators is set, it will be passed on to the list view, causing its CSS node to carry the .separators style class. For rubberband selection, a node with name rubberband is used.

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

Accessibility

GtkColumnView uses the AccessibleRole.tree_grid role, header title widgets are using the AccessibleRole.column_header role. The row widgets are using the AccessibleRole.row role, and individual cells are using the AccessibleRole.grid_cell role

Constructors

new

@classmethod
def new(cls, model: SelectionModel | None = ...) -> Widget

Creates a new GtkColumnView.

You most likely want to call ColumnView.append_column to add columns next.

Parameters:

  • model — the list model to use

Methods

append_column

def append_column(self, column: ColumnViewColumn) -> None

Appends the column to the end of the columns in self.

Parameters:

  • column — a column that hasn't been added to a GtkColumnView yet

get_columns

def get_columns(self) -> Gio.ListModel

Gets the list of columns in this column view.

This list is constant over the lifetime of self and can be used to monitor changes to the columns of self by connecting to the Gio.ListModel.items-changed signal.

get_enable_rubberband

def get_enable_rubberband(self) -> bool

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

get_header_factory

def get_header_factory(self) -> ListItemFactory | None

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

get_model

def get_model(self) -> SelectionModel | None

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

get_reorderable

def get_reorderable(self) -> bool

Returns whether columns are reorderable.

get_row_factory

def get_row_factory(self) -> ListItemFactory | None

Gets the factory set via ColumnView.set_row_factory.

get_show_column_separators

def get_show_column_separators(self) -> bool

Returns whether the list should show separators between columns.

get_show_row_separators

def get_show_row_separators(self) -> bool

Returns whether the list should show separators between rows.

get_single_click_activate

def get_single_click_activate(self) -> bool

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

get_sorter

def get_sorter(self) -> Sorter | None

Returns a special sorter that reflects the users sorting choices in the column view.

To allow users to customizable sorting by clicking on column headers, this sorter needs to be set on the sort model underneath the model that is displayed by the view.

See ColumnViewColumn.set_sorter for setting up per-column sorting.

Here is an example:

gtk_column_view_column_set_sorter (column, sorter);
gtk_column_view_append_column (view, column);
sorter = g_object_ref (gtk_column_view_get_sorter (view)));
model = gtk_sort_list_model_new (store, sorter);
selection = gtk_no_selection_new (model);
gtk_column_view_set_model (view, selection);

get_tab_behavior

def get_tab_behavior(self) -> ListTabBehavior

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

insert_column

def insert_column(self, position: int, column: ColumnViewColumn) -> None

Inserts a column at the given position in the columns of self.

If column is already a column of self, it will be repositioned.

Parameters:

  • position — the position to insert column at
  • column — the column to insert

remove_column

def remove_column(self, column: ColumnViewColumn) -> None

Removes the column from the list of columns of self.

Parameters:

  • column — a column that's part of self

scroll_to

def scroll_to(self, pos: int, column: ColumnViewColumn | None, flags: ListScrollFlags | int, scroll: ScrollInfo | None = ...) -> None

Scroll to the row at the given position - or cell if a column is given - and performs the actions specified in flags.

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

Parameters:

  • pos — position of the item. Must be less than the number of items in the view.
  • column — The column to scroll to or NULL to not scroll columns
  • flags — actions to perform
  • scroll — details of how to perform the scroll operation or None to scroll into view

set_enable_rubberband

def set_enable_rubberband(self, enable_rubberband: bool) -> None

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

Parameters:

  • enable_rubberband — whether to enable rubberband selection

set_header_factory

def set_header_factory(self, factory: ListItemFactory | None = ...) -> None

Sets the factory to use for populating the ListHeader objects used in section headers.

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

Parameters:

  • factory — the factory to use

set_model

def set_model(self, model: SelectionModel | None = ...) -> None

Sets the model to use.

This must be a SelectionModel.

Parameters:

  • model — the model to use

set_reorderable

def set_reorderable(self, reorderable: bool) -> None

Sets whether columns should be reorderable by dragging.

Parameters:

  • reorderable — whether columns should be reorderable

set_row_factory

def set_row_factory(self, factory: ListItemFactory | None = ...) -> None

Sets the factory used for configuring rows.

The factory must be for configuring ColumnViewRow objects.

If this factory is not set - which is the default - then the defaults will be used.

This factory is not used to set the widgets displayed in the individual cells. For that see GtkColumnViewColumn.set_factory and GtkColumnViewCell.

Parameters:

  • factory — The row factory

set_show_column_separators

def set_show_column_separators(self, show_column_separators: bool) -> None

Sets whether the list should show separators between columns.

Parameters:

  • show_column_separators — whether to show column separators

set_show_row_separators

def set_show_row_separators(self, show_row_separators: bool) -> None

Sets whether the list should show separators between rows.

Parameters:

  • show_row_separators — whether to show row separators

set_single_click_activate

def set_single_click_activate(self, single_click_activate: bool) -> None

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

Parameters:

  • single_click_activate — whether to activate items on single click

set_tab_behavior

def set_tab_behavior(self, tab_behavior: ListTabBehavior | int) -> None

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 columnview.

Parameters:

  • tab_behavior — The desired tab behavior

sort_by_column

def sort_by_column(self, column: ColumnViewColumn | None, direction: SortType | int) -> None

Sets the sorting of the view.

This function should be used to set up the initial sorting. At runtime, users can change the sorting of a column view by clicking on the list headers.

This call only has an effect if the sorter returned by ColumnView.get_sorter is set on a sort model, and ColumnViewColumn.set_sorter has been called on column to associate a sorter with the column.

If column is unset, the view will be unsorted.

Parameters:

  • column — the column to sort by
  • direction — the direction to sort in

Properties

columns

columns: Gio.ListModel  # read-only

The list of columns.

enable_rubberband

enable_rubberband: bool  # read/write

Allow rubberband selection.

header_factory

header_factory: ListItemFactory  # read/write

Factory for creating header widgets.

The factory must be for configuring ListHeader objects.

model

model: SelectionModel  # read/write

Model for the items displayed.

reorderable

reorderable: bool  # read/write

Whether columns are reorderable.

row_factory

row_factory: ListItemFactory  # read/write

The factory used for configuring rows.

The factory must be for configuring ColumnViewRow objects.

show_column_separators

show_column_separators: bool  # read/write

Show separators between columns.

show_row_separators

show_row_separators: bool  # read/write

Show separators between rows.

single_click_activate

single_click_activate: bool  # read/write

Activate rows on single click and select them on hover.

sorter

sorter: Sorter  # read-only

Sorter with the sorting choices of the user.

tab_behavior

tab_behavior: ListTabBehavior | int  # read/write

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

Signals

activate

def on_activate(self, position: int) -> None: ...

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

This allows for a convenient way to handle activation in a columnview. See ListItem.set_activatable for details on how to use this signal.