GtkColumnView

GtkColumnView — A widget for displaying lists in multiple columns

Properties

GListModel * columns Read
gboolean enable-rubberband Read / Write
GListModel * model Read / Write
gboolean reorderable Read / Write
gboolean show-column-separators Read / Write
gboolean show-row-separators Read / Write
gboolean single-click-activate Read / Write
GtkSorter * sorter Read

Signals

void activate Run Last

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── GtkWidget
            ╰── GtkColumnView

Implemented Interfaces

GtkColumnView implements AtkImplementorIface, GtkBuildable, GtkConstraintTarget and GtkScrollable.

Includes

#include <gtk/gtk.h>

Description

GtkColumnView is a widget to present a view into 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 “show-row-separators” and “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. If the provided model is not a GtkSelectionModel, GtkColumnView will wrap it in a GtkSingleSelection. For models that allow multiple selected items, it is possible to turn on _rubberband selection_, using “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 gtk_column_view_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 gtk_column_view_column_set_sorter(). The initial sort order can be set with gtk_column_view_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 “reorderable” and “resizable” properties.

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

CSS nodes

1
2
3
4
5
6
7
8
9
10
columnview[.column-separators]
├── header
   ├── <column header>
   
   ╰── <column header>

├── listview


╰── [rubberband]

GtkColumnView uses a single CSS node named columnview. It may carry the .column-separators style class, when “show-column-separators” property is set. Header widets 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 “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.

Functions

gtk_column_view_new ()

GtkWidget *
gtk_column_view_new (void);

Creates a new empty GtkColumnView.

You most likely want to call gtk_column_view_set_factory() to set up a way to map its items to widgets and gtk_column_view_set_model() to set a model to provide items next.

Returns

a new GtkColumnView


gtk_column_view_append_column ()

void
gtk_column_view_append_column (GtkColumnView *self,
                               GtkColumnViewColumn *column);

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

Parameters

self

a GtkColumnView

 

column

a GtkColumnViewColumn that hasn't been added to a GtkColumnView yet

 

gtk_column_view_insert_column ()

void
gtk_column_view_insert_column (GtkColumnView *self,
                               guint position,
                               GtkColumnViewColumn *column);

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

self

a GtkColumnView

 

position

the position to insert column at

 

column

the GtkColumnViewColumn to insert

 

gtk_column_view_remove_column ()

void
gtk_column_view_remove_column (GtkColumnView *self,
                               GtkColumnViewColumn *column);

Removes the column from the list of columns of self .

Parameters

self

a GtkColumnView

 

column

a GtkColumnViewColumn that's part of self

 

gtk_column_view_get_columns ()

GListModel *
gtk_column_view_get_columns (GtkColumnView *self);

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 GListModel:items-changed signal.

Parameters

self

a GtkColumnView

 

Returns

The list managing the columns.

[transfer none]


gtk_column_view_get_model ()

GListModel *
gtk_column_view_get_model (GtkColumnView *self);

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

Parameters

self

a GtkColumnView

 

Returns

The model in use.

[nullable][transfer none]


gtk_column_view_set_model ()

void
gtk_column_view_set_model (GtkColumnView *self,
                           GListModel *model);

Sets the GListModel to use.

If the model is a GtkSelectionModel, it is used for managing the selection. Otherwise, self creates a GtkSingleSelection for the selection.

Parameters

self

a GtkColumnView

 

model

the model to use or NULL for none.

[allow-none][transfer none]

gtk_column_view_get_sorter ()

GtkSorter *
gtk_column_view_get_sorter (GtkColumnView *self);

Returns the sorter associated with 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(s) underneath the model that is displayed by the view.

See gtk_column_view_column_get_sorter() for setting up per-column sorting.

Parameters

self

a GtkColumnView

 

Returns

the GtkSorter of self .

[transfer none]


gtk_column_view_get_show_row_separators ()

gboolean
gtk_column_view_get_show_row_separators
                               (GtkColumnView *self);

Returns whether the list should show separators between rows.

Parameters

self

a GtkColumnView

 

Returns

TRUE if the list shows separators


gtk_column_view_set_show_row_separators ()

void
gtk_column_view_set_show_row_separators
                               (GtkColumnView *self,
                                gboolean show_row_separators);

Sets whether the list should show separators between rows.

Parameters

self

a GtkColumnView

 

show_row_separators

TRUE to show row separators

 

gtk_column_view_get_show_column_separators ()

gboolean
gtk_column_view_get_show_column_separators
                               (GtkColumnView *self);

Returns whether the list should show separators between columns.

Parameters

self

a GtkColumnView

 

Returns

TRUE if the list shows column separators


gtk_column_view_set_show_column_separators ()

void
gtk_column_view_set_show_column_separators
                               (GtkColumnView *self,
                                gboolean show_column_separators);

Sets whether the list should show separators between columns.

Parameters

self

a GtkColumnView

 

show_column_separators

TRUE to show column separators

 

gtk_column_view_sort_by_column ()

void
gtk_column_view_sort_by_column (GtkColumnView *self,
                                GtkColumnViewColumn *column,
                                GtkSortType direction);

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 gtk_column_view_get_sorter() is set on a sort model, and gtk_column_view_column_set_sorter() has been called on column to associate a sorter with the column.

If column is NULL, the view will be unsorted.

Parameters

self

a GtkColumnView

 

column

the GtkColumnViewColumn to sort by, or NULL.

[allow-none]

direction

the direction to sort in

 

gtk_column_view_set_single_click_activate ()

void
gtk_column_view_set_single_click_activate
                               (GtkColumnView *self,
                                gboolean single_click_activate);

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

Parameters

self

a GtkColumnView

 

single_click_activate

TRUE to activate items on single click

 

gtk_column_view_get_single_click_activate ()

gboolean
gtk_column_view_get_single_click_activate
                               (GtkColumnView *self);

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

Parameters

self

a GtkColumnView

 

Returns

TRUE if rows are activated on single click


gtk_column_view_set_reorderable ()

void
gtk_column_view_set_reorderable (GtkColumnView *self,
                                 gboolean reorderable);

Sets whether columns should be reorderable by dragging.

Parameters

self

a GtkColumnView

 

reorderable

whether columns should be reorderable

 

gtk_column_view_get_reorderable ()

gboolean
gtk_column_view_get_reorderable (GtkColumnView *self);

Returns whether columns are reorderable.

Parameters

self

a GtkColumnView

 

Returns

TRUE if columns are reorderable


gtk_column_view_set_enable_rubberband ()

void
gtk_column_view_set_enable_rubberband (GtkColumnView *self,
                                       gboolean enable_rubberband);

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

Parameters

self

a GtkColumnView

 

enable_rubberband

TRUE to enable rubberband selection

 

gtk_column_view_get_enable_rubberband ()

gboolean
gtk_column_view_get_enable_rubberband (GtkColumnView *self);

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

Parameters

self

a GtkColumnView

 

Returns

TRUE if rubberband selection is enabled

Types and Values

GtkColumnView

typedef struct _GtkColumnView GtkColumnView;

GtkColumnView is the simple list implementation for GTK's list widgets.

Property Details

The “columns” property

  “columns”                  GListModel *

The list of columns

Owner: GtkColumnView

Flags: Read


The “enable-rubberband” property

  “enable-rubberband”        gboolean

Allow rubberband selection

Owner: GtkColumnView

Flags: Read / Write

Default value: FALSE


The “model” property

  “model”                    GListModel *

Model for the items displayed

Owner: GtkColumnView

Flags: Read / Write


The “reorderable” property

  “reorderable”              gboolean

Whether columns are reorderable

Owner: GtkColumnView

Flags: Read / Write

Default value: TRUE


The “show-column-separators” property

  “show-column-separators”   gboolean

Show separators between columns

Owner: GtkColumnView

Flags: Read / Write

Default value: FALSE


The “show-row-separators” property

  “show-row-separators”      gboolean

Show separators between rows

Owner: GtkColumnView

Flags: Read / Write

Default value: FALSE


The “single-click-activate” property

  “single-click-activate”    gboolean

Activate rows on single click and select them on hover

Owner: GtkColumnView

Flags: Read / Write

Default value: FALSE


The “sorter” property

  “sorter”                   GtkSorter *

Sorter with the sorting choices of the user

Owner: GtkColumnView

Flags: Read

Signal Details

The “activate” signal

void
user_function (GtkColumnView *self,
               guint          position,
               gpointer       user_data)

The ::activate signal is 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 gtk_list_item_set_activatable() for details on how to use this signal.

Parameters

self

The GtkColumnView

 

position

position of item to activate

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last