Trying hard with a custom cellrenderer.



Hi all. I have a class I want to render in a treeview.

This class represents an URLResource:

class URLResource {
...
};

So I want to have:

class MyColRecord : public Gtk::TreeModelColumnRecord {
 Gtk::TreeModelColumn<URLResource*> urlresource_;

...
};

I want to render this url as a button in the column and I want that
button to be able to be pushed
so that when you push the button you can listen to the resource (the
url is a sound file). So I started a custom cellrenderer:

class URLCellRenderer : public Gtk::CellRenderer {
private:
    // the property whose value will be set by Gtk before a cell is rendered
    Glib::Property<URL*> property_url_;
public:
    URLCellRenderer() :  Glib::ObjectBase(typeid(URLCellRenderer)),
            Gtk::CellRenderer(),  property_url_ (*this, "url") //
giving the property a name
    {}

    void get_size_vfunc(Gtk::Widget& widget,  Gdk::Rectangle const *
cell_area,
    int* x_offset,  int* y_offset,  int* width,  int* height) const
    {
        *width = 60;
        *height = 39;
    }

    void render_vfunc(Glib::RefPtr<Gdk::Drawable> const & window,
                      Gtk::Widget& widget,
                      Gdk::Rectangle const & background_area,
                      Gdk::Rectangle const & cell_area,
                      Gdk::Rectangle const & expose_area,
                      Gtk::CellRendererState flags)  {

      //Don't know what to do here.
    }
};

I added the treeviewcolumn to the view like this:

tvcolurl.pack_start(cellrurl);
tvcolurl.add_attribute(cellrurl, "url", c.url);

view.append_column(tvcolurl, c.url);

When appending data, I get an error like this:

(pruebacell:7666): GLib-GObject-CRITICAL **: g_value_copy: assertion
`g_value_type_compatible (G_VALUE_TYPE (src_value), G_VALUE_TYPE
(dest_value))' failed

I don't know either how to embed a button in the column or how should
I write the render function. Any suggestions? Thanks in advance.


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