Re: [gtkmm] adding widgets to TreeView column cells
- From: Matthew Walton <matthew alledora co uk>
- To: gtkmm-list gnome org
- Subject: Re: [gtkmm] adding widgets to TreeView column cells
- Date: Wed, 02 Jul 2003 10:01:08 +0100
(forgot to CC the list, re-sending to list only)
TreeViews achieve their display through widgets which are subclasses of
Gtk::CellRenderer. Out of the box, GTK comes with three -
CellRendererText, for rendering text strings, CellRendererPixbuf, for
rendering images, and CellRendererToggle, for rendering boolean values
as a checkbox. You cannot add arbitrary widgets to a TreeView. If you
want to display another kind of data, you must either use a cell data
function to convert the data in the model to something one of the
existing renderers can display, or you can write your own CellRenderer.
While it might be nice if you could put any widget you liked into a
TreeView, I'm not entirely sure it would be very practical.
As for adding a Gtk::Label* to a treeview column - well, you can do it
if you really want to. What that achieves is storing a pointer to a
Gtk::Label in the tree model. You haven't posted the code you used to
add the column to the treeview, but it looks like it's attempting to
render it using a CellRendererText, which clearly isn't going to work as
it has no idea what a Gtk::Label* is or what to do with it. If you want
to have text strings in your TreeView, stick to columns containing
Glib::ustring, and CellRendererText to display it. Remember TreeView is
a model/view/controller-based system, so what you're storing in the
model bears very little relevance to what you're displaying, and you
could point two different TreeViews at it and display the data in
completely different ways with each one.
If you really, really want to store a label in a treemodel column, use
the TreeView's ability to associate functions with data retrieval
(set_cell_data_func() or something like that I think) so that it will
follow the pointer and call Gtk::Label::get_text() when it wants to
display it. I can't imagine why you'd want to do that though.
Radio buttons would require a new cellrenderer, although you could fake
them using cellrenderertoggle and some callbacks on the selection and
toggle signals, but this would be complicated and also would give you a
broken UI, as they'd still look like check buttons.
Hopefully this long ramble is of some mild use to you.
Peter Gasper wrote:
I created a treeview following the "TreeView - Editable Cells" example in the book.
I can do that ok. What I can't figure out how to do is add and instantiate
TreeModelColumn's that aren't types like bool, int, and ustring. For example:
how could one add a label or radiobutton? Is this even possible?
thanks.
ex:
normally you have:
//Tree model columns:
class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumns()
{ add(m_col_id);}
Gtk::TreeModelColumn<unsigned int> m_col_id;
};
then later:
row[m_Columns.m_col_id] = 1;
So I try (as an example that actually compiles):
Gtk::TreeModelColumn<Gtk::Label*> m_label;
then later:
row[m_Columns.m_label]= new Gtk::Label::Label("Hi");
the label fails to display and gives the following runtime error:
(lb:29476): GLib-GObject-WARNING **: unable to set property `text' of type `gchararray' from value of type `GtkLabel'
this example is probably not the right way to go about it, but just given to help
you understand what I'm trying to do.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]