Base class to display cell contents in a GtkTreeView.
The GtkCellRenderer is a base class of a set of objects used for rendering a cell to a GdkDrawable. 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.
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 GtkEntry.
Changes of edited cells are not automatically saved in the model; this has to be done by hand: Connect to the "edited" (text) or "toggled" (toggle) signal and set the new values in the store.
Example 21. Text and toggle cell renderers
<?php /* * This sample shows how to use the * GtkCellRenderer along with GtkTreeView */ // Creates the main window $window = new GtkWindow; $window->set_title('Cell Renderers'); $window->connect_simple('destroy', array('Gtk', 'main_quit')); $window->set_position(GTK::WIN_POS_CENTER); $window->set_default_size(280,140); // Creates the data model $model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_BOOLEAN); // Creates the view to display the content $view = new GtkTreeView($model); // Creates two columns $column1 = new GtkTreeViewColumn('Language'); $column2 = new GtkTreeViewColumn('Open Source?'); // Add the columns to the view $view->append_column($column1); $view->append_column($column2); // Creates two cell-renderers $cell_renderer1 = new GtkCellRendererText(); $cell_renderer2 = new GtkCellRendererToggle(); // change the property 'width' $cell_renderer1->set_property('width', 180); $cell_renderer2->set_property('width', -1); // Pack the cell-renderers $column1->pack_start($cell_renderer1, true); $column2->pack_start($cell_renderer2, true); // link the renderers to the model $column1->set_attributes($cell_renderer1, 'text', 0); $column2->set_attributes($cell_renderer2, 'active', 1); // Add some data $model->append(array('PHP', true)); $model->append(array('Python', true)); $model->append(array('Delphi', false)); $model->append(array('Visual Basic', false)); // pack the view inside the window $window->add($view); // show the window $window->show_all(); Gtk::main(); ?>
activate() editing_canceled() get_fixed_size() Retrieves an array containing the width and height of the cell. render() set_fixed_size() Sets the renderer size to the specified width and height, independent of the properties set. start_editing() stop_editing()
Use get_property and set_property methods to access these.
cell-background: The background color of the cell as a string. Default: NULL cell-background-gdk: The background color of the cell as a GtkColor cell-background-set: If TRUE the cell background color is set by this cellrenderer. Default: FALSE. height: Changes the height of the cell. Allowed values >= -1. Default: -1 is-expanded: If TRUE the row has children and it is expanded to show the children. is-expander: If TRUE the row has children. Default: FALSE. sensitive: If TRUE the cell is displayed as sensitive. If FALSE, in grayscale. Default: TRUE. visible: If TRUE the cell is displayed. Default: TRUE. width: The fixed width of the cell in pixels. Allowed values >= -1. Default: -1. xalign: The fraction of free space to the left of the cell. yalign: The fraction of free space above the cell. xpad: The amount of padding to the left and right of the cell. ypad: The amount of padding above and below cell.
"editing-canceled" Emitted when the user cancels the of editing a cell. "editing-started" Emitted when a cell starts to be edited.