Gtk.TreeViewColumn

g GObject.GInterface GObject.GInterface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.CellLayout Gtk.CellLayout GObject.GInterface->Gtk.CellLayout GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.TreeViewColumn Gtk.TreeViewColumn GObject.InitiallyUnowned->Gtk.TreeViewColumn GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Buildable->Gtk.TreeViewColumn Gtk.CellLayout->Gtk.TreeViewColumn

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gtk.Buildable (10), Gtk.CellLayout (9)

Structs:

GObject.ObjectClass (5)

class

new ()

class

new_with_area (area)

add_attribute (cell_renderer, attribute, column)

cell_get_position (cell_renderer)

cell_get_size (cell_area)

cell_is_visible ()

cell_set_cell_data (tree_model, iter, is_expander, is_expanded)

clear ()

clear_attributes (cell_renderer)

clicked ()

focus_cell (cell)

get_alignment ()

get_button ()

get_clickable ()

get_expand ()

get_fixed_width ()

get_max_width ()

get_min_width ()

get_reorderable ()

get_resizable ()

get_sizing ()

get_sort_column_id ()

get_sort_indicator ()

get_sort_order ()

get_spacing ()

get_title ()

get_tree_view ()

get_visible ()

get_widget ()

get_width ()

get_x_offset ()

pack_end (cell, expand)

pack_start (cell, expand)

queue_resize ()

set_alignment (xalign)

set_attributes (cell_renderer, **attributes)

set_cell_data_func (cell_renderer, func, *func_data)

set_clickable (clickable)

set_expand (expand)

set_fixed_width (fixed_width)

set_max_width (max_width)

set_min_width (min_width)

set_reorderable (reorderable)

set_resizable (resizable)

set_sizing (type)

set_sort_column_id (sort_column_id)

set_sort_indicator (setting)

set_sort_order (order)

set_spacing (spacing)

set_title (title)

set_visible (visible)

set_widget (widget)

Virtual Methods

Inherited:

GObject.Object (7), Gtk.Buildable (10), Gtk.CellLayout (9)

do_clicked ()

Properties

Name

Type

Flags

Short Description

alignment

float

r/w/en

X Alignment of the column header text or widget

cell-area

Gtk.CellArea

r/w/co

The Gtk.CellArea used to layout cells

clickable

bool

r/w/en

Whether the header can be clicked

expand

bool

r/w/en

Column gets share of extra width allocated to the widget

fixed-width

int

r/w/en

Current fixed width of the column

max-width

int

r/w/en

Maximum allowed width of the column

min-width

int

r/w/en

Minimum allowed width of the column

reorderable

bool

r/w/en

Whether the column can be reordered around the headers

resizable

bool

r/w/en

Column is user-resizable

sizing

Gtk.TreeViewColumnSizing

r/w/en

Resize mode of the column

sort-column-id

int

r/w/en

Logical sort column ID this column sorts on when selected for sorting

sort-indicator

bool

r/w/en

Whether to show a sort indicator

sort-order

Gtk.SortType

r/w/en

Sort direction the sort indicator should indicate

spacing

int

r/w/en

Space which is inserted between cells

title

str

r/w

Title to appear in column header

visible

bool

r/w/en

Whether to display the column

widget

Gtk.Widget

r/w

Widget to put in column header button instead of column title

width

int

r

Current width of the column

x-offset

int

r

Current X position of the column

Signals

Inherited:

GObject.Object (1)

Name

Short Description

clicked

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.InitiallyUnowned

r

Class Details

class Gtk.TreeViewColumn(title='', cell_renderer=None, **attributes)
Bases:

GObject.InitiallyUnowned, Gtk.Buildable, Gtk.CellLayout

Abstract:

No

Structure:

Gtk.TreeViewColumnClass

The Gtk.TreeViewColumn object represents a visible column in a Gtk.TreeView widget. It allows to set properties of the column header, and functions as a holding pen for the cell renderers which determine how the data in the column is displayed.

Please refer to the tree widget conceptual overview for an overview of all the objects and data types related to the tree widget and how they work together.

classmethod new()[source]
Returns:

A newly created Gtk.TreeViewColumn.

Return type:

Gtk.TreeViewColumn

Creates a new Gtk.TreeViewColumn.

classmethod new_with_area(area)[source]
Parameters:

area (Gtk.CellArea) – the Gtk.CellArea that the newly created column should use to layout cells.

Returns:

A newly created Gtk.TreeViewColumn.

Return type:

Gtk.TreeViewColumn

Creates a new Gtk.TreeViewColumn using area to render its cells.

New in version 3.0.

add_attribute(cell_renderer, attribute, column)[source]
Parameters:
  • cell_renderer (Gtk.CellRenderer) – the Gtk.CellRenderer to set attributes on

  • attribute (str) – An attribute on the renderer

  • column (int) – The column position on the model to get the attribute from.

Adds an attribute mapping to the list in self. The column is the column of the model to get a value from, and the attribute is the parameter on cell_renderer to be set from the value. So for example if column 2 of the model contains strings, you could have the “text” attribute of a Gtk.CellRendererText get its values from column 2.

cell_get_position(cell_renderer)[source]
Parameters:

cell_renderer (Gtk.CellRenderer) – a Gtk.CellRenderer

Returns:

None if cell does not belong to self or a tuple containing:

x_offset:

the horizontal position of cell within self

width:

the width of cell

Return type:

(x_offset: int, width: int) or None

Obtains the horizontal position and size of a cell in a column. If the cell is not found in the column None is returned.

cell_get_size(cell_area)[source]
Parameters:

cell_area (Gdk.Rectangle or None) – The area a cell in the column will be allocated, or None

Returns:

x_offset:

location to return x offset of a cell relative to cell_area, or None

y_offset:

location to return y offset of a cell relative to cell_area, or None

width:

location to return width needed to render a cell, or None

height:

location to return height needed to render a cell, or None

Return type:

(x_offset: int, y_offset: int, width: int, height: int)

Obtains the width and height needed to render the column. This is used primarily by the Gtk.TreeView.

cell_is_visible()[source]
Returns:

True, if any of the cells packed into the self are currently visible

Return type:

bool

Returns True if any of the cells packed into the self are visible. For this to be meaningful, you must first initialize the cells with Gtk.TreeViewColumn.cell_set_cell_data()

cell_set_cell_data(tree_model, iter, is_expander, is_expanded)[source]
Parameters:

Sets the cell renderer based on the tree_model and iter. That is, for every attribute mapping in self, it will get a value from the set column on the iter, and use that value to set the attribute on the cell renderer. This is used primarily by the Gtk.TreeView.

clear()[source]

Unsets all the mappings on all renderers on the self.

clear_attributes(cell_renderer)[source]
Parameters:

cell_renderer (Gtk.CellRenderer) – a Gtk.CellRenderer to clear the attribute mapping on.

Clears all existing attributes previously set with Gtk.TreeViewColumn.set_attributes().

clicked()[source]

Emits the “clicked” signal on the column. This function will only work if self is clickable.

focus_cell(cell)[source]
Parameters:

cell (Gtk.CellRenderer) – A Gtk.CellRenderer

Sets the current keyboard focus to be at cell, if the column contains 2 or more editable and activatable cells.

New in version 2.2.

get_alignment()[source]
Returns:

The current alignent of self.

Return type:

float

Returns the current x alignment of self. This value can range between 0.0 and 1.0.

get_button()[source]
Returns:

The button for the column header.

Return type:

Gtk.Widget

Returns the button used in the treeview column header

New in version 3.0.

get_clickable()[source]
Returns:

True if user can click the column header.

Return type:

bool

Returns True if the user can click on the header for the column.

get_expand()[source]
Returns:

True if the column expands to fill available space.

Return type:

bool

Returns True if the column expands to fill available space.

New in version 2.4.

get_fixed_width()[source]
Returns:

The fixed width of the column.

Return type:

int

Gets the fixed width of the column. This may not be the actual displayed width of the column; for that, use Gtk.TreeViewColumn.get_width().

get_max_width()[source]
Returns:

The maximum width of the self.

Return type:

int

Returns the maximum width in pixels of the self, or -1 if no maximum width is set.

get_min_width()[source]
Returns:

The minimum width of the self.

Return type:

int

Returns the minimum width in pixels of the self, or -1 if no minimum width is set.

get_reorderable()[source]
Returns:

True if the self can be reordered by the user.

Return type:

bool

Returns True if the self can be reordered by the user.

get_resizable()[source]
Returns:

True, if the self can be resized.

Return type:

bool

Returns True if the self can be resized by the end user.

get_sizing()[source]
Returns:

The type of self.

Return type:

Gtk.TreeViewColumnSizing

Returns the current type of self.

get_sort_column_id()[source]
Returns:

the current sort_column_id for this column, or -1 if this column can’t be used for sorting.

Return type:

int

Gets the logical sort_column_id that the model sorts on when this column is selected for sorting. See Gtk.TreeViewColumn.set_sort_column_id().

get_sort_indicator()[source]
Returns:

whether the sort indicator arrow is displayed

Return type:

bool

Gets the value set by Gtk.TreeViewColumn.set_sort_indicator().

get_sort_order()[source]
Returns:

the sort order the sort indicator is indicating

Return type:

Gtk.SortType

Gets the value set by Gtk.TreeViewColumn.set_sort_order().

get_spacing()[source]
Returns:

the spacing of self.

Return type:

int

Returns the spacing of self.

get_title()[source]
Returns:

the title of the column. This string should not be modified or freed.

Return type:

str

Returns the title of the widget.

get_tree_view()[source]
Returns:

The tree view wherein column has been inserted if any, None otherwise.

Return type:

Gtk.Widget or None

Returns the Gtk.TreeView wherein self has been inserted. If column is currently not inserted in any tree view, None is returned.

New in version 2.12.

get_visible()[source]
Returns:

whether the column is visible or not. If it is visible, then the tree will show the column.

Return type:

bool

Returns True if self is visible.

get_widget()[source]
Returns:

The Gtk.Widget in the column header, or None

Return type:

Gtk.Widget or None

Returns the Gtk.Widget in the button on the column header. If a custom widget has not been set then None is returned.

get_width()[source]
Returns:

The current width of self.

Return type:

int

Returns the current size of self in pixels.

get_x_offset()[source]
Returns:

The current X offset of self.

Return type:

int

Returns the current X offset of self in pixels.

New in version 3.2.

pack_end(cell, expand)[source]
Parameters:

Adds the cell to end of the column. If expand is False, then the cell is allocated no more space than it needs. Any unused space is divided evenly between cells for which expand is True.

pack_start(cell, expand)[source]
Parameters:

Packs the cell into the beginning of the column. If expand is False, then the cell is allocated no more space than it needs. Any unused space is divided evenly between cells for which expand is True.

queue_resize()[source]

Flags the column, and the cell renderers added to this column, to have their sizes renegotiated.

New in version 2.8.

set_alignment(xalign)[source]
Parameters:

xalign (float) – The alignment, which is between [0.0 and 1.0] inclusive.

Sets the alignment of the title or custom widget inside the column header. The alignment determines its location inside the button – 0.0 for left, 0.5 for center, 1.0 for right.

set_attributes(cell_renderer, **attributes)[source]
Parameters:

cell_renderer (Gtk.CellRenderer) – the Gtk.CellRenderer we’re setting the attributes of

Sets the attributes in the list as the attributes of self. The attributes should be in attribute/column order, as in Gtk.TreeViewColumn.add_attribute(). All existing attributes are removed, and replaced with the new attributes.

set_cell_data_func(cell_renderer, func, *func_data)[source]
Parameters:

Sets the Gtk.TreeCellDataFunc to use for the column. This function is used instead of the standard attributes mapping for setting the column value, and should set the value of self's cell renderer as appropriate. func may be None to remove an older one.

set_clickable(clickable)[source]
Parameters:

clickable (bool) – True if the header is active.

Sets the header to be active if clickable is True. When the header is active, then it can take keyboard focus, and can be clicked.

set_expand(expand)[source]
Parameters:

expand (bool) – True if the column should expand to fill available space.

Sets the column to take available extra space. This space is shared equally amongst all columns that have the expand set to True. If no column has this option set, then the last column gets all extra space. By default, every column is created with this False.

Along with “fixed-width”, the “expand” property changes when the column is resized by the user.

New in version 2.4.

set_fixed_width(fixed_width)[source]
Parameters:

fixed_width (int) – The new fixed width, in pixels, or -1.

If fixed_width is not -1, sets the fixed width of self; otherwise unsets it. The effective value of fixed_width is clamped between the minimum and maximum width of the column; however, the value stored in the “fixed-width” property is not clamped. If the column sizing is Gtk.TreeViewColumnSizing.GROW_ONLY or Gtk.TreeViewColumnSizing.AUTOSIZE, setting a fixed width overrides the automatically calculated width. Note that fixed_width is only a hint to GTK+; the width actually allocated to the column may be greater or less than requested.

Along with “expand”, the “fixed-width” property changes when the column is resized by the user.

set_max_width(max_width)[source]
Parameters:

max_width (int) – The maximum width of the column in pixels, or -1.

Sets the maximum width of the self. If max_width is -1, then the maximum width is unset. Note, the column can actually be wider than max width if it’s the last column in a view. In this case, the column expands to fill any extra space.

set_min_width(min_width)[source]
Parameters:

min_width (int) – The minimum width of the column in pixels, or -1.

Sets the minimum width of the self. If min_width is -1, then the minimum width is unset.

set_reorderable(reorderable)[source]
Parameters:

reorderable (bool) – True, if the column can be reordered.

If reorderable is True, then the column can be reordered by the end user dragging the header.

set_resizable(resizable)[source]
Parameters:

resizable (bool) – True, if the column can be resized

If resizable is True, then the user can explicitly resize the column by grabbing the outer edge of the column button. If resizable is True and sizing mode of the column is Gtk.TreeViewColumnSizing.AUTOSIZE, then the sizing mode is changed to Gtk.TreeViewColumnSizing.GROW_ONLY.

set_sizing(type)[source]
Parameters:

type (Gtk.TreeViewColumnSizing) – The Gtk.TreeViewColumnSizing.

Sets the growth behavior of self to type.

set_sort_column_id(sort_column_id)[source]
Parameters:

sort_column_id (int) – The sort_column_id of the model to sort on.

Sets the logical sort_column_id that this column sorts on when this column is selected for sorting. Doing so makes the column header clickable.

set_sort_indicator(setting)[source]
Parameters:

setting (bool) – True to display an indicator that the column is sorted

Call this function with a setting of True to display an arrow in the header button indicating the column is sorted. Call Gtk.TreeViewColumn.set_sort_order() to change the direction of the arrow.

set_sort_order(order)[source]
Parameters:

order (Gtk.SortType) – sort order that the sort indicator should indicate

Changes the appearance of the sort indicator.

This does not actually sort the model. Use Gtk.TreeViewColumn.set_sort_column_id() if you want automatic sorting support. This function is primarily for custom sorting behavior, and should be used in conjunction with Gtk.TreeSortable.set_sort_column_id() to do that. For custom models, the mechanism will vary.

The sort indicator changes direction to indicate normal sort or reverse sort. Note that you must have the sort indicator enabled to see anything when calling this function; see Gtk.TreeViewColumn.set_sort_indicator().

set_spacing(spacing)[source]
Parameters:

spacing (int) – distance between cell renderers in pixels.

Sets the spacing field of self, which is the number of pixels to place between cell renderers packed into it.

set_title(title)[source]
Parameters:

title (str) – The title of the self.

Sets the title of the self. If a custom widget has been set, then this value is ignored.

set_visible(visible)[source]
Parameters:

visible (bool) – True if the self is visible.

Sets the visibility of self.

set_widget(widget)[source]
Parameters:

widget (Gtk.Widget or None) – A child Gtk.Widget, or None.

Sets the widget in the header to be widget. If widget is None, then the header button is set with a Gtk.Label set to the title of self.

do_clicked() virtual

Emits the “clicked” signal on the column. This function will only work if tree_column is clickable.

Signal Details

Gtk.TreeViewColumn.signals.clicked(tree_view_column)
Signal Name:

clicked

Flags:

RUN_LAST

Parameters:

tree_view_column (Gtk.TreeViewColumn) – The object which received the signal

Property Details

Gtk.TreeViewColumn.props.alignment
Name:

alignment

Type:

float

Default Value:

0.0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

X Alignment of the column header text or widget

Gtk.TreeViewColumn.props.cell_area
Name:

cell-area

Type:

Gtk.CellArea

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The Gtk.CellArea used to layout cell renderers for this column.

If no area is specified when creating the tree view column with Gtk.TreeViewColumn.new_with_area() a horizontally oriented Gtk.CellAreaBox will be used.

New in version 3.0.

Gtk.TreeViewColumn.props.clickable
Name:

clickable

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the header can be clicked

Gtk.TreeViewColumn.props.expand
Name:

expand

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Column gets share of extra width allocated to the widget

Gtk.TreeViewColumn.props.fixed_width
Name:

fixed-width

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Current fixed width of the column

Gtk.TreeViewColumn.props.max_width
Name:

max-width

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Maximum allowed width of the column

Gtk.TreeViewColumn.props.min_width
Name:

min-width

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Minimum allowed width of the column

Gtk.TreeViewColumn.props.reorderable
Name:

reorderable

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the column can be reordered around the headers

Gtk.TreeViewColumn.props.resizable
Name:

resizable

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Column is user-resizable

Gtk.TreeViewColumn.props.sizing
Name:

sizing

Type:

Gtk.TreeViewColumnSizing

Default Value:

Gtk.TreeViewColumnSizing.GROW_ONLY

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Resize mode of the column

Gtk.TreeViewColumn.props.sort_column_id
Name:

sort-column-id

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Logical sort column ID this column sorts on when selected for sorting. Setting the sort column ID makes the column header clickable. Set to -1 to make the column unsortable.

New in version 2.18.

Gtk.TreeViewColumn.props.sort_indicator
Name:

sort-indicator

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether to show a sort indicator

Gtk.TreeViewColumn.props.sort_order
Name:

sort-order

Type:

Gtk.SortType

Default Value:

Gtk.SortType.ASCENDING

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Sort direction the sort indicator should indicate

Gtk.TreeViewColumn.props.spacing
Name:

spacing

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Space which is inserted between cells

Gtk.TreeViewColumn.props.title
Name:

title

Type:

str

Default Value:

''

Flags:

READABLE, WRITABLE

Title to appear in column header

Gtk.TreeViewColumn.props.visible
Name:

visible

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether to display the column

Gtk.TreeViewColumn.props.widget
Name:

widget

Type:

Gtk.Widget

Default Value:

None

Flags:

READABLE, WRITABLE

Widget to put in column header button instead of column title

Gtk.TreeViewColumn.props.width
Name:

width

Type:

int

Default Value:

0

Flags:

READABLE

Current width of the column

Gtk.TreeViewColumn.props.x_offset
Name:

x-offset

Type:

int

Default Value:

0

Flags:

READABLE

Current X position of the column