Re: [gtkmm] adding widgets to TreeView column cells



Note also that there is a customcellrenderer example (adds a combo-style
column) in the tarball and lots of discussion about this in the archive.
There are also plans to add more common cellrenderers to GTK+ in future
- but you should ask on gtk-list about these plans.
 
I don't particularly like having to implement custom cell renders
instead of just hooking existing widgets up somehow, but it seems like a
fairly common problem with other toolkits too.

On Wed, 2003-07-02 at 11:01, Matthew Walton wrote:
> (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.
> >  
> >
> 
> 
> 
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
-- 
Murray Cumming
murray usa net
www.murrayc.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]