How to control GTK4 scaling (running under Windows)?

Greetings there,

I’m developing an application in Ruby using GTK4, and would like to understand how to work with scaling under GTK. Specifically, I would like to display images at native pixel size (that is, without rescaling), while allowing surrounding text to be automatically rescaled. Is this possible?

I have my images computed in memory, then I am copying into a Pixbuf, which I am then displaying using Cairo within a DrawingArea. (Happy to hear better alternatives.) I specify the size of the DrawingArea using the content_width and content_height properties set to the number of pixels in the originally computed image, hoping for native 1:1 pixel mapping.

I have recently changed displays, the new one is higher resolution, so I have increased my scaling in Windows to 200%.

And now when I display the image, it gets scaled up, together with the text around it. This makes sense as default, to keep the UI layout the same.

However I would like to go back to displaying pixels 1:1 on screen.

How may I achieve this?

Thank you in advance.

Hi,

The DrawingArea works in virtual pixels, not in physical ones.
You can do manual scaling by getting the current scale factor when drawing.

Have you tried using a GtkPicture?

Thank you, that’s exactly what I needed: using the scaling_factor to set content_width/content_height of the DrawingArea worked.

Thank you for the suggestion of using GtkPicture… I switched to it now. Fingers crossed!

I am displaying many (appx. 1000-15000) images, each of which has some processing.

Any suggestions where to tell GtkColumnView how many items to create? It is creating and populating about a 70-100 items, of which only about 2 or 3 fit on screen… this makes scrolling pretty slow… like up to 30 seconds between updates when dragging the scrollbar.

With Cairo this was tolerable, because in that approach the actual processing and displaying of images was only triggered by the Cairo drawing function, which was only called for items that were actually displayed onscreen… with this new GtkPicture approach however a large number of items/images get created/bound/processed, taking considerable time (many seconds)… while many of these aren’t ever actually displayed on screen.

1 Like

Hi,

Glad to hear it works :slight_smile:

I would suggest to create a separate topic, for better visibility.

Thank you kindly.

Thank you, yes, good idea; I created a separate topic now. Here’s hoping.

For future readers, I just found this information: HowDoI/HiDpi - GNOME Wiki!