Gtk::CellRendererPixbuf: unable to set property 'surface'



Hi,

I'm trying to set a "surface" property onĀ Gtk::CellRendererPixbuf
and getting a gtk error:

"unable to set property 'surface' of type 'CairoSurface' from value of type
'glibmm__CustomBoxed_N5Cairo6RefPtrINS_7SurfaceEEE'"


This is the code:

-------------------------------------------

class GscMainWindowIconView : public Gtk::IconView {

    Gtk::CellRendererPixbuf cell_renderer_pixbuf;
    // ...

    GscMainWindowIconView()
    {
            //...
            this->pack_start(cell_renderer_pixbuf, false);
            this->set_cell_data_func(cell_renderer_pixbuf,
                    sigc::mem_fun(this, &GscMainWindowIconView::on_cell_data));
    }

    void on_cell_data(const Gtk::TreeModel::const_iterator& iter)
    {
            Gtk::TreeRow row = *iter;
            Glib::RefPtr<Gdk::Pixbuf> pixbuf = row[col_pixbuf];

            // I couldn't find the gtkmm version of gdk_cairo_surface_create_from_pixbuf(),
            // that's why I create the surface this way.
            Cairo::Format format = Cairo::FORMAT_ARGB32;
            if (pixbuf->get_n_channels() == 3) {
                    format = Cairo::FORMAT_RGB24;
            }
        Cairo::RefPtr<Cairo::Surface> surface = get_window()->create_similar_image_surface(
                            format, pixbuf->get_width(), pixbuf->get_height(), get_scale_factor());

            // THIS IS THE PROBLEM
            cell_renderer_pixbuf.property_surface().set_value(surface);
    }

}

-------------------------------------------

Note that if I change Cairo surface creation and property setting
to C-style, everything works (although I'm not sure whether the "surface"
variable leaks? The docs don't mention):

cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(
        pixbuf->gobj(), get_scale_factor(), get_window()->gobj());
g_object_set(G_OBJECT(cell_renderer_pixbuf.gobj()), "surface", surface, NULL);


This all comes from trying to port the code from this bug report:
https://bugzilla.gnome.org/show_bug.cgi?id=765167#c5


Thanks,
Alexander



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