Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a GtkPixbuf from a stock item llike (new_from_stock)?

Tags:

gtk

I want to get a stock item to use it in a treeview but I can't get it as a pixbuf directly as there is no new_from_stock method for pixbufs!!

like image 255
Foss Avatar asked Aug 23 '13 12:08

Foss


2 Answers

say you want to get a pixbuf from stock_item.

There are 2 ways:

First (easy):

pixbuf = gtk_widget_render_icon ( widget, stock_item, size )

Second (hard):

You need to look for it in the list of default icon factories:

icon_set = gtk_style_lookup_icon_set ( style, stock_item )

OR:

icon_set = gtk_icon_factory_lookup_default ( $stock_item )

then check available sizes with get_sizes. Check if the size you want is available or get the largest size which will be the last in the returned list. Then you need to render it to get the pixbuf:

pixbuf = gtk_icon_set_render_icon ( icon_set, style, direction, state, size, widget )

Then scale it to whatever size you want using:

gdk_pixbuf_scale_simple ( pixbuf, width, height, GdkInterpType )

Hope you got it

like image 158
ophidion Avatar answered Sep 17 '22 12:09

ophidion


Are you aware of the icon-name property in GtkCellRendererPixbuf? That should solve the problem of showing a stock icon in a treeview.

like image 38
Jussi Kukkonen Avatar answered Sep 19 '22 12:09

Jussi Kukkonen