Re: [gtkmm] Mapping from a TreeModel data to a CellRenderer



On Wed, 2002-08-07 at 23:30, ERDI Gergo wrote:
> 
> I'm missing the part of the puzzle where I can connect a stock
> CellRenderer to an element stored in a Model. I have something like this:
> 
> class Res
> {
>    std::string id;
> public:
>     Res (const std::string &id_): id (id_) {
>     }
>      
>     std::string get_id () const {
>         return id;
>     }
> };
> 
>     Gtk::TreeModelColumn<Res*> col_text;
>     Gtk::TreeModel::ColumnRecord cols;
>     cols.add (col_text);
>   
>     lstore = Gtk::ListStore::create (cols);
>     set_model (lstore);

>     Gtk::TreeViewColumn *view_column = new Gtk::TreeViewColumn ("");
>     Gtk::CellRenderer   *cell_renderer = new Gtk::CellRendererText;
>     view_column->pack_start (*Gtk::manage (cell_renderer), true);
>     view_column->set_renderer (*cell_renderer, col_text);

For other readers, these 4 lines are only necessary when doing unusual
stuff. See the gtkmm book.
    
>     append_column (*Gtk::manage (view_column));
> 
> so here's the tricky part: How do I create a CellRenderer subclass that
> re-uses the CellRendererText implementation, but takes the string to
> render from the Res* supplied by the model, by calling get_id on it?

Have you looked at the cellrenderercustom example:
http://www.gtkmm.org/gtkmm2/examples/cellrenderercustom/
I haven't looked at it much yet.

-- 
Murray Cumming
murrayc usa net
www.murrayc.com




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