Gtk.Image set_pixel_size stopped scaling image in GTK 4.19.2

Hi all,

I’m developing a GTK app, built as a Flatpak using GNOME Nightly.

In my UI, I use a custom button-like widget that contains a child Gtk.Image. As the window is resized, the widget and the image should scale dynamically. To handle this, I’ve overridden the size_allocate function to:

  • Calculate the new size for the image
  • Call size_allocate() on the image to resize it
  • Call set_pixel_size() on the image to scale it

This setup had been working fine. However, starting today, I noticed that the image now appears very blurry. I suspect this change is due to a recent update in GTK brought in through GNOME Nightly.

I could not pinpoint the exact commit but I found this GTK 4.19.2 NEWS update which seems related to the behavior I’m seeing:

* GtkImage:
 - Change the sizing behavior for paintables. Stop scaling them up

So my questions are:

  • What’s the correct approach now for dynamically scaling images with Gtk.Image?
  • Can I still achieve this effect using Gtk.Image, or do I have to resort to a lower-level API like Gdk.Texture or Gdk.Paintable directly?
1 Like

Did you try using gtkpicture instead? But I tried gtkimage a bit now too and there seems to be something weird going on as it scales in height. It’s this mr: iconhelper: Stop scaling up paintables (!8627) · Merge requests · GNOME / gtk · GitLab

I’ve currently pinned my flatpak manifest to GNOME 48 until I have more time to properly address this. The MR does indeed suggest using Gtk.Picture for scalable icons, so I’ll move towards that direction I guess.

There may be a typo on this line, width should probably be w: gtk/gtkiconhelper.c · main · GNOME / gtk · GitLab

This does not help with this topic though, gtkpicture should be used for scaling images.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.