iter_o = my_buffer.get_iter_at_offset (0)
pt = Gdk.Paintable.new_empty (900, 128)
img = Gtk.Image.new_from_paintable (pt)
img.set_from_icon_name ("br_sura_dark")
my_buffer.insert_paintable (iter_o, pt)
After you call Gtk.Image.set_from_icon_name()
, the Image no longer tracks the Paintable, so you’re just adding the empty Paintable. Instead, you can use Gtk.IconTheme.lookup_icon()
to get a Gtk.IconPaintable
:
https://lazka.github.io/pgi-docs/#Gtk-4.0/classes/IconTheme.html#Gtk.IconTheme.lookup_icon
1 Like
thanks
iter_o = my_buffer.get_iter_at_offset (0)
icon_theme = Gtk.IconTheme.get_for_display (self.get_display ())
pt = icon_theme.lookup_icon ("br", None, 500, 1, self.get_direction (), 0);
my_buffer.insert_paintable (iter_o, pt)
It actually works but there is a problem
It gives me a square image when I want different dimensions
Icons are generally square, I think. You could use Gdk.Texture.new_from_filename()
with the full path, which could be in your app’s DATADIR.
1 Like
iter_o = my_buffer.get_iter_at_offset (0)
tr = Gdk.Texture.new_from_filename ("file.png")
my_buffer.insert_paintable (iter_o, tr)
Thanks, this is easier and nicer
This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.