How to add a custom cell renderer to a Gtk::IconView



Hello list,

I encountered the following problem: Under Gtk+ it is possible to have a
GktIconView and cast it to a GtkCellLayout via the GTK_CELL_LAYOUT(obj)
macro. Then I could add a custom cell renderer and set attributes to it.

Now I have implemented my cell renderer in C++/Gtkmm and would like to
add it to my Gtk::IconView. And since the class does not provide a
pack_start() functionality like TreeView, I would have to go and find my
own way to do it...

The first problem is that the IconView class does not inherit (in the
traditional C++ way) from Gtk::CellLayout. Second, the
reinterpret_cast<> did not work either. There is no function in the
Gtk::IconView API that lets me convert to a CellLayout, or in the
Gtk::CellLayout API to create it from an IconView... Third, I tried to
do something like

Gtk::CellLayout *cl = Glib::wrap( GTK_CELL_LAYOUT( my_icon_view.gobj() ) );
cl->pack_start( renderer, false );
cl->add_attribute( renderer->property_blah(), columns.blah );
....

While it compiles, the application crashed with a reinterpret_cast
failure reported. The only thing that worked so far was to take my Gtk+
implementation of the renderer, add it to my project and create a
GtkIconView, cast it to GTK_CELL_LAYOUT, add the renderer with
properties, and at the end wrap it into a Gtk::IconView and work from
there as it were pure Gtkmm.

I wonder though, is this the best way? I would like to not handle Gtk+
objects directly in my code. Can anyone make a suggestion as to how to
add a custom cell renderer to a Gtk::IconView in a "best practice"
approach? Your help and time are greatly appreciated.

Kind regards,
Todor


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