Gtk.CellRenderer¶
class — extends GObject.InitiallyUnowned
:::warning Deprecated since 4.10 This API is deprecated. :::
An object for rendering a single cell
The GtkCellRenderer is a base class of a set of objects used for
rendering a cell to a cairo_t. These objects are used primarily by
the GtkTreeView widget, though they aren’t tied to them in any
specific way. It is worth noting that GtkCellRenderer is not a
GtkWidget and cannot be treated as such.
The primary use of a GtkCellRenderer is for drawing a certain graphical
elements on a cairo_t. Typically, one cell renderer is used to
draw many cells on the screen. To this extent, it isn’t expected that a
CellRenderer keep any permanent state around. Instead, any state is set
just prior to use using GObjects property system. Then, the
cell is measured using CellRenderer.get_preferred_size. Finally, the cell
is rendered in the correct location using CellRenderer.snapshot.
There are a number of rules that must be followed when writing a new
GtkCellRenderer. First and foremost, it’s important that a certain set
of properties will always yield a cell renderer of the same size,
barring a style change. The GtkCellRenderer also has a number of
generic properties that are expected to be honored by all children.
Beyond merely rendering a cell, cell renderers can optionally
provide active user interface elements. A cell renderer can be
“activatable” like GtkCellRendererToggle,
which toggles when it gets activated by a mouse click, or it can be
“editable” like GtkCellRendererText, which
allows the user to edit the text using a widget implementing the
GtkCellEditable interface, e.g. GtkEntry.
To make a cell renderer activatable or editable, you have to
implement the GtkCellRendererClass.activate or
GtkCellRendererClass.start_editing virtual functions, respectively.
Many properties of GtkCellRenderer and its subclasses have a
corresponding “set” property, e.g. “cell-background-set” corresponds
to “cell-background”. These “set” properties reflect whether a property
has been set or not. You should not set them independently.
Methods¶
activate¶
def activate(self, event: Gdk.Event, widget: Widget, path: str, background_area: Gdk.Rectangle, cell_area: Gdk.Rectangle, flags: CellRendererState | int) -> bool
:::warning Deprecated since 4.10 This API is deprecated. :::
Passes an activate event to the cell renderer for possible processing.
Some cell renderers may use events; for example, GtkCellRendererToggle
toggles when it gets a mouse click.
Parameters:
event— aGdkEventwidget— widget that received the eventpath— widget-dependent string representation of the event location; e.g. forGtkTreeView, a string representation ofGtkTreePathbackground_area— background area as passed to gtk_cell_renderer_render()cell_area— cell area as passed to gtk_cell_renderer_render()flags— render flags
get_aligned_area¶
def get_aligned_area(self, widget: Widget, flags: CellRendererState | int, cell_area: Gdk.Rectangle) -> Gdk.Rectangle
:::warning Deprecated since 4.10 This API is deprecated. :::
Gets the aligned area used by cell inside cell_area. Used for finding
the appropriate edit and focus rectangle.
Parameters:
widget— theGtkWidgetthis cell will be rendering toflags— render flagscell_area— cell area which would be passed to gtk_cell_renderer_render()
get_alignment¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Fills in xalign and yalign with the appropriate values of cell.
get_fixed_size¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Fills in width and height with the appropriate size of cell.
get_is_expanded¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Checks whether the given GtkCellRenderer is expanded.
get_is_expander¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Checks whether the given GtkCellRenderer is an expander.
get_padding¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Fills in xpad and ypad with the appropriate values of cell.
get_preferred_height¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Retrieves a renderer’s natural size when rendered to widget.
Parameters:
widget— theGtkWidgetthis cell will be rendering to
get_preferred_height_for_width¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Retrieves a cell renderers’s minimum and natural height if it were rendered to
widget with the specified width.
Parameters:
widget— theGtkWidgetthis cell will be rendering towidth— the size which is available for allocation
get_preferred_size¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Retrieves the minimum and natural size of a cell taking into account the widget’s preference for height-for-width management.
Parameters:
widget— theGtkWidgetthis cell will be rendering to
get_preferred_width¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Retrieves a renderer’s natural size when rendered to widget.
Parameters:
widget— theGtkWidgetthis cell will be rendering to
get_preferred_width_for_height¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Retrieves a cell renderers’s minimum and natural width if it were rendered to
widget with the specified height.
Parameters:
widget— theGtkWidgetthis cell will be rendering toheight— the size which is available for allocation
get_request_mode¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Gets whether the cell renderer prefers a height-for-width layout or a width-for-height layout.
get_sensitive¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Returns the cell renderer’s sensitivity.
get_state¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Translates the cell renderer state to GtkStateFlags,
based on the cell renderer and widget sensitivity, and
the given GtkCellRendererState.
Parameters:
widget— aGtkWidgetcell_state— cell renderer state
get_visible¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Returns the cell renderer’s visibility.
is_activatable¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Checks whether the cell renderer can do something when activated.
set_alignment¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Sets the renderer’s alignment within its available space.
Parameters:
xalign— the x alignment of the cell rendereryalign— the y alignment of the cell renderer
set_fixed_size¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Sets the renderer size to be explicit, independent of the properties set.
Parameters:
width— the width of the cell renderer, or -1height— the height of the cell renderer, or -1
set_is_expanded¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Sets whether the given GtkCellRenderer is expanded.
Parameters:
is_expanded— whethercellshould be expanded
set_is_expander¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Sets whether the given GtkCellRenderer is an expander.
Parameters:
is_expander— whethercellis an expander
set_padding¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Sets the renderer’s padding.
Parameters:
xpad— the x padding of the cell rendererypad— the y padding of the cell renderer
set_sensitive¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Sets the cell renderer’s sensitivity.
Parameters:
sensitive— the sensitivity of the cell
set_visible¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Sets the cell renderer’s visibility.
Parameters:
visible— the visibility of the cell
snapshot¶
def snapshot(self, snapshot: Snapshot, widget: Widget, background_area: Gdk.Rectangle, cell_area: Gdk.Rectangle, flags: CellRendererState | int) -> None
:::warning Deprecated since 4.10 This API is deprecated. :::
Invokes the virtual render function of the GtkCellRenderer. The three
passed-in rectangles are areas in cr. Most renderers will draw within
cell_area; the xalign, yalign, xpad, and ypad fields of the GtkCellRenderer
should be honored with respect to cell_area. background_area includes the
blank space around the cell, and also the area containing the tree expander;
so the background_area rectangles for all cells tile to cover the entire
window.
Parameters:
snapshot— aGtkSnapshotto draw towidget— the widget owningwindowbackground_area— entire cell area (including tree expanders and maybe padding on the sides)cell_area— area normally rendered by a cell rendererflags— flags that affect rendering
start_editing¶
def start_editing(self, event: Gdk.Event | None, widget: Widget, path: str, background_area: Gdk.Rectangle, cell_area: Gdk.Rectangle, flags: CellRendererState | int) -> CellEditable | None
:::warning Deprecated since 4.10 This API is deprecated. :::
Starts editing the contents of this cell, through a new GtkCellEditable
widget created by the GtkCellRendererClass.start_editing virtual function.
Parameters:
event— aGdkEventwidget— widget that received the eventpath— widget-dependent string representation of the event location; e.g. forGtkTreeView, a string representation ofGtkTreePathbackground_area— background area as passed to gtk_cell_renderer_render()cell_area— cell area as passed to gtk_cell_renderer_render()flags— render flags
stop_editing¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Informs the cell renderer that the editing is stopped.
If canceled is True, the cell renderer will emit the
GtkCellRenderer::editing-canceled signal.
This function should be called by cell renderer implementations
in response to the GtkCellEditable::editing-done signal of
GtkCellEditable.
Parameters:
canceled—Trueif the editing has been canceled
Virtual methods¶
do_activate¶
def do_activate(self, event: Gdk.Event, widget: Widget, path: str, background_area: Gdk.Rectangle, cell_area: Gdk.Rectangle, flags: CellRendererState | int) -> bool
:::warning Deprecated since 4.10 This API is deprecated. :::
Passes an activate event to the cell renderer for possible processing.
Some cell renderers may use events; for example, GtkCellRendererToggle
toggles when it gets a mouse click.
Parameters:
event— aGdkEventwidget— widget that received the eventpath— widget-dependent string representation of the event location; e.g. forGtkTreeView, a string representation ofGtkTreePathbackground_area— background area as passed to gtk_cell_renderer_render()cell_area— cell area as passed to gtk_cell_renderer_render()flags— render flags
do_editing_canceled¶
Signal gets emitted when the user cancels the process of editing a cell.
do_editing_started¶
Signal gets emitted when a cell starts to be edited.
do_get_aligned_area¶
def do_get_aligned_area(self, widget: Widget, flags: CellRendererState | int, cell_area: Gdk.Rectangle) -> Gdk.Rectangle
:::warning Deprecated since 4.10 This API is deprecated. :::
Gets the aligned area used by cell inside cell_area. Used for finding
the appropriate edit and focus rectangle.
Parameters:
widget— theGtkWidgetthis cell will be rendering toflags— render flagscell_area— cell area which would be passed to gtk_cell_renderer_render()
do_get_preferred_height¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Retrieves a renderer’s natural size when rendered to widget.
Parameters:
widget— theGtkWidgetthis cell will be rendering to
do_get_preferred_height_for_width¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Retrieves a cell renderers’s minimum and natural height if it were rendered to
widget with the specified width.
Parameters:
widget— theGtkWidgetthis cell will be rendering towidth— the size which is available for allocation
do_get_preferred_width¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Retrieves a renderer’s natural size when rendered to widget.
Parameters:
widget— theGtkWidgetthis cell will be rendering to
do_get_preferred_width_for_height¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Retrieves a cell renderers’s minimum and natural width if it were rendered to
widget with the specified height.
Parameters:
widget— theGtkWidgetthis cell will be rendering toheight— the size which is available for allocation
do_get_request_mode¶
:::warning Deprecated since 4.10 This API is deprecated. :::
Gets whether the cell renderer prefers a height-for-width layout or a width-for-height layout.
do_snapshot¶
def do_snapshot(self, snapshot: Snapshot, widget: Widget, background_area: Gdk.Rectangle, cell_area: Gdk.Rectangle, flags: CellRendererState | int) -> None
:::warning Deprecated since 4.10 This API is deprecated. :::
Invokes the virtual render function of the GtkCellRenderer. The three
passed-in rectangles are areas in cr. Most renderers will draw within
cell_area; the xalign, yalign, xpad, and ypad fields of the GtkCellRenderer
should be honored with respect to cell_area. background_area includes the
blank space around the cell, and also the area containing the tree expander;
so the background_area rectangles for all cells tile to cover the entire
window.
Parameters:
snapshot— aGtkSnapshotto draw towidget— the widget owningwindowbackground_area— entire cell area (including tree expanders and maybe padding on the sides)cell_area— area normally rendered by a cell rendererflags— flags that affect rendering
do_start_editing¶
def do_start_editing(self, event: Gdk.Event | None, widget: Widget, path: str, background_area: Gdk.Rectangle, cell_area: Gdk.Rectangle, flags: CellRendererState | int) -> CellEditable | None
:::warning Deprecated since 4.10 This API is deprecated. :::
Starts editing the contents of this cell, through a new GtkCellEditable
widget created by the GtkCellRendererClass.start_editing virtual function.
Parameters:
event— aGdkEventwidget— widget that received the eventpath— widget-dependent string representation of the event location; e.g. forGtkTreeView, a string representation ofGtkTreePathbackground_area— background area as passed to gtk_cell_renderer_render()cell_area— cell area as passed to gtk_cell_renderer_render()flags— render flags
Properties¶
cell_background¶
cell_background_rgba¶
Cell background as a GdkRGBA
cell_background_set¶
editing¶
height¶
is_expanded¶
is_expander¶
mode¶
sensitive¶
visible¶
width¶
xalign¶
xpad¶
yalign¶
ypad¶
Signals¶
editing-canceled¶
This signal gets emitted when the user cancels the process of editing a cell. For example, an editable cell renderer could be written to cancel editing when the user presses Escape.
See also: CellRenderer.stop_editing.
editing-started¶
This signal gets emitted when a cell starts to be edited.
The intended use of this signal is to do special setup
on editable, e.g. adding a GtkEntryCompletion or setting
up additional columns in a GtkComboBox.
See CellEditable.start_editing for information on the lifecycle of
the editable and a way to do setup that doesn’t depend on the renderer.
Note that GTK doesn't guarantee that cell renderers will
continue to use the same kind of widget for editing in future
releases, therefore you should check the type of editable
before doing any specific setup, as in the following example: