Re: [Vala] using a GLib.Icon in an IconView



Hi,

I'm working with a Gtk.IconView, and need to put standard icons in it. I 
have several ThemedIcons, and want to use them there, but IconView 
expects a Gdk.Pixbuf. How can I do that? I've been unable to find how to 
render a GLib.Icon in a Gdk.Pixbuf.

Gtk.IconView uses a Gdk.CellRendererPixbuf to render the icons in the
iconview. Gtk.IconView has a property "gicon" which can be used to set
the icon from a GLib.Icon

In other words, you need a Gtk.TreeModel with a column for your GLib.Icon

Then use the Gtk.CellLayout.set_attributes function to set the "gicon"
property of the CellRenderPixbuf in the IconView to the number of the
column in the TreeModel that holds the gicon

The only slight issue is obtaining the CellRendererPixbuf as it is not
available easily from the IconView object, however something like this
should work:

Gtk.CellRendererPixbuf get_cr_pixbuf(Gtk.IconView icon_view) {
        var crs = icon_view.get_cells();
        foreach (var cr in crs) {
                if (cr is Gtk.CellRendererPixbuf) {
                        return cr;
                }
        }
        stdout.printf("Can't find pixbuf cellrenderer (shouldn't happen)");
        assert_not_reached();
}

var cr_pixbuf = get_cr_pixbuf(icon_view);
icon_view.set_attributes(cr_pixbuf, "gicon", GICON_COLUMN_NUMBER);

If you need any more pointers, just ask :)

Hope this helps

--
Andrew



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