Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
144 lines (101 sloc) 4.69 KB
.. _cellrenderers:
:class:`Gtk.CellRenderer` widgets are used to display information within widgets such as the
:class:`Gtk.TreeView` or :class:`Gtk.ComboBox`. They work closely with the
associated widgets and are very powerful, with lots of configuration options for
displaying a large amount of data in different ways. There are seven
:class:`Gtk.CellRenderer` widgets which can be used for different purposes:
* :class:`Gtk.CellRendererText`
* :class:`Gtk.CellRendererToggle`
* :class:`Gtk.CellRendererPixbuf`
* :class:`Gtk.CellRendererCombo`
* :class:`Gtk.CellRendererProgress`
* :class:`Gtk.CellRendererSpinner`
* :class:`Gtk.CellRendererSpin`
* :class:`Gtk.CellRendererAccel`
A :class:`Gtk.CellRendererText` renders a given text in its cell, using the font,
color and style information provided by its properties. The text will be
ellipsized if it is too long and the "ellipsize" property allows it.
By default, text in :class:`Gtk.CellRendererText` widgets is not editable. This
can be changed by setting the value of the "editable" property to ``True``:
.. code-block:: python
cell.set_property("editable", True)
You can then connect to the "edited" signal and update your :class:`Gtk.TreeModel`
.. image:: ../images/cellrenderertext_example.png
.. literalinclude:: ../examples/
:class:`Gtk.CellRendererToggle` renders a toggle button in a cell. The button is
drawn as a radio- or checkbutton, depending on the "radio" property. When
activated, it emits the "toggled" signal.
As a :class:`Gtk.CellRendererToggle` can have two states, active and not active,
you most likely want to bind the "active" property on the cell renderer
to a boolean value in the model, thus causing the check button to reflect the
state of the model.
.. image:: ../images/cellrenderertoggle_example.png
.. literalinclude:: ../examples/
A :class:`Gtk.CellRendererPixbuf` can be used to render an image in a cell. It
allows to render either a given :class:`Gdk.Pixbuf` (set via the "pixbuf"
property) or a named icon (set via the "icon-name" property).
.. image:: ../images/cellrendererpixbuf_example.png
.. literalinclude:: ../examples/
:class:`Gtk.CellRendererCombo` renders text in a cell like
:class:`Gtk.CellRendererText` from which it is derived. But while the latter
offers a simple entry to edit the text, :class:`Gtk.CellRendererCombo` offers a
:class:`Gtk.ComboBox` widget to edit the text. The values to display in the combo
box are taken from the :class:`Gtk.TreeModel` specified in the "model" property.
The combo cell renderer takes care of adding a text cell renderer to the combo
box and sets it to display the column specified by its "text-column" property.
A :class:`Gtk.CellRendererCombo` can operate in two modes. It can be used with
and without an associated :class:`Gtk.Entry` widget, depending on the value of
the "has-entry" property.
.. image:: ../images/cellrenderercombo_example.png
.. literalinclude:: ../examples/
:class:`Gtk.CellRendererProgress` renders a numeric value as a progress bar in a
cell. Additionally, it can display a text on top of the progress bar.
The percentage value of the progress bar can be modified by changing the "value"
property. Similar to :class:`Gtk.ProgressBar`, you can enable the *activity mode*
by incrementing the "pulse" property instead of the "value" property.
.. image:: ../images/cellrendererprogress_example.png
.. literalinclude:: ../examples/
:class:`Gtk.CellRendererSpin` renders text in a cell like
:class:`Gtk.CellRendererText` from which it is derived. But while the latter
offers a simple entry to edit the text, :class:`Gtk.CellRendererSpin` offers a
:class:`Gtk.SpinButton` widget. Of course, that means that the text has to be
parseable as a floating point number.
The range of the spinbutton is taken from the adjustment property of the cell
renderer, which can be set explicitly or mapped to a column in the tree model,
like all properties of cell renders. :class:`Gtk.CellRendererSpin` also has
properties for the climb rate and the number of digits to display.
.. image:: ../images/cellrendererspin_example.png
.. literalinclude:: ../examples/
You can’t perform that action at this time.