Search code examples
imagegtkvala

Vala get icon from theme with spesific size?


I want to get an icon from system and show it in Gtk.Image but in a spesific size.

Gtk.Image.icon_size property is an enum, it isn't setting pixel width or height. (Gtk.IconSize)

This is how I get icon from system theme:

var icon = new Gtk.Image.from_icon_name("icon_name", 0);
...

// Something like `icon.set_size(150, 150);` ?

But even it is a .svg file in .icons folder, it is displaying as too small like 16x16.

I want to display it like 150x150.

Thanks!


Solution

  • Here is how I've solved:

    // 150 is pixel size:
    var icon_theme = IconTheme.get_default();
    var pixbuf_icon = icon_theme.load_icon("icon-name", 150, IconLookupFlags.FORCE_SVG);
    
    var final_img = new Image.from_pixbuf(pixbuf_icon);
    // Use final_img...