matthias
matthias

Reputation: 2181

In Gtk, is it possible to have one cell renderer per treeview row?

In Gtk+ it is possible to have several cell renderers per column, however I want to have different cell renderers in different rows. For example, I'd like to list the properties of an object in a tree view. For boolean properties a toggle button would be much simpler to use than editing the GtkCellRendererText and type in TRUE or FALSE.

I know that I can react to the row data by setting a callback via gtk_tree_view_column_set_cell_data_func(). But in the callback, the cell renderer is already fixed and I can only change its appearance.

Edit: ptomato pointed to how it could be done in Vala. I took this information and build a C-based cell renderer that takes a GObject and a list store (assuming the first column to contain property names) to show a custom cell depending on the type of the property. I also subclassed a tree view widget that combines this for easier usage. Both components can be find at Github.

Upvotes: 6

Views: 2112

Answers (1)

ptomato
ptomato

Reputation: 57854

Here's how dconf-editor does it: subclass GtkCellRenderer to make a custom renderer, make a property called renderer that returns a GtkCellRendererText, GtkCellRendererToggle, etc. depending on what is needed, and override all the GtkCellRenderer signals such as get_size, render, activate, etc. to pass them along to the underlying renderer.

It's done in Vala but it shouldn't be too hard to convert to C.

Upvotes: 6

Related Questions