Skip to content

Gtk.ColumnViewColumn

class — extends GObject.Object

Represents the columns in a GtkColumnView.

The main ingredient for a GtkColumnViewColumn is the GtkListItemFactory that tells the columnview how to create cells for this column from items in the model.

Columns have a title, and can optionally have a header menu set with ColumnViewColumn.set_header_menu.

A sorter can be associated with a column using ColumnViewColumn.set_sorter, to let users influence sorting by clicking on the column header.

Constructors

new

@classmethod
def new(cls, title: str | None = ..., factory: ListItemFactory | None = ...) -> ColumnViewColumn

Creates a new GtkColumnViewColumn that uses the given factory for mapping items to widgets.

You most likely want to call ColumnView.append_column next.

The function takes ownership of the argument, so you can write code like:

column = gtk_column_view_column_new (_("Name"),
  gtk_builder_list_item_factory_new_from_resource ("/name.ui"));

Parameters:

  • title — Title to use for this column
  • factory — The factory to populate items with

Methods

get_column_view

def get_column_view(self) -> ColumnView | None

Gets the column view that's currently displaying this column.

If self has not been added to a column view yet, NULL is returned.

get_expand

def get_expand(self) -> bool

Returns whether this column should expand.

get_factory

def get_factory(self) -> ListItemFactory | None

Gets the factory that's currently used to populate list items for this column.

get_fixed_width

def get_fixed_width(self) -> int

Gets the fixed width of the column.

get_header_menu

def get_header_menu(self) -> Gio.MenuModel | None

Gets the menu model that is used to create the context menu for the column header.

get_id

def get_id(self) -> str | None

Returns the ID set with ColumnViewColumn.set_id.

get_resizable

def get_resizable(self) -> bool

Returns whether this column is resizable.

get_sorter

def get_sorter(self) -> Sorter | None

Returns the sorter that is associated with the column.

get_title

def get_title(self) -> str | None

Returns the title set with ColumnViewColumn.set_title.

get_visible

def get_visible(self) -> bool

Returns whether this column is visible.

set_expand

def set_expand(self, expand: bool) -> None

Sets the column to take available extra space.

The extra space is shared equally amongst all columns that have are set to expand.

Parameters:

  • expand — whether this column should expand to fill available space

set_factory

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

Sets the GtkListItemFactory to use for populating list items for this column.

Parameters:

  • factory — the factory to use

set_fixed_width

def set_fixed_width(self, fixed_width: int) -> None

Sets the fixed width of the column.

If fixed_width is -1, the fixed width of the column is unset.

Setting a fixed width overrides the automatically calculated width. Interactive resizing also sets the “fixed-width” property.

Parameters:

  • fixed_width — the new fixed width, or -1

set_header_menu

def set_header_menu(self, menu: Gio.MenuModel | None = ...) -> None

Sets the menu model that is used to create the context menu for the column header.

Parameters:

  • menu — a GMenuModel

set_id

def set_id(self, id: str | None = ...) -> None

Sets the id of this column.

GTK makes no use of this, but applications can use it when storing column view configuration.

It is up to callers to ensure uniqueness of IDs.

Parameters:

  • id — ID to use for this column

set_resizable

def set_resizable(self, resizable: bool) -> None

Sets whether this column should be resizable by dragging.

Parameters:

  • resizable — whether this column should be resizable

set_sorter

def set_sorter(self, sorter: Sorter | None = ...) -> None

Associates a sorter with the column.

If sorter is unset, the column will not let users change the sorting by clicking on its header.

This sorter can be made active by clicking on the column header, or by calling ColumnView.sort_by_column.

See ColumnView.get_sorter for the necessary steps for setting up customizable sorting for ColumnView.

Parameters:

  • sorter — the GtkSorter to associate with column

set_title

def set_title(self, title: str | None = ...) -> None

Sets the title of this column.

The title is displayed in the header of a GtkColumnView for this column and is therefore user-facing text that should be translated.

Parameters:

  • title — Title to use for this column

set_visible

def set_visible(self, visible: bool) -> None

Sets whether this column should be visible in views.

Parameters:

  • visible — whether this column should be visible

Properties

column_view

column_view: ColumnView  # read-only

The GtkColumnView this column is a part of.

expand

expand: bool  # read/write

Column gets share of extra width allocated to the view.

factory

factory: ListItemFactory  # read/write

Factory for populating list items.

The factory must be for configuring ColumnViewCell objects.

fixed_width

fixed_width: int  # read/write

If not -1, this is the width that the column is allocated, regardless of the size of its content.

header_menu

header_menu: Gio.MenuModel  # read/write

Menu model used to create the context menu for the column header.

id

id: str  # read/write

An ID for the column.

GTK is not currently using the ID for anything, but it can be used by applications when saving column view configurations.

It is up to applications to ensure uniqueness of IDs.

resizable

resizable: bool  # read/write

Whether this column is resizable.

sorter

sorter: Sorter  # read/write

Sorter for sorting items according to this column.

title

title: str  # read/write

Title displayed in the header.

visible

visible: bool  # read/write

Whether this column is visible.