Vertically expand GtkPicture inside a GtkScrolledWindow

So I have a scrolled window containing a GtkBox with some text and a few images.
The behavior I want is for the images that are GtkPicture to expand as much as possible horizontally without making the window horizontally scrolled, but I can’t seem to find an easy way to accomplish this.

An example tree of my widgets would be as follows

+ GtkScrolledWindow
|---+ GtkBox
    |---- GtkTextView
    |---- GtkPicture
    |---- GtkPicture
    |---- GtkTextView

The GtkScrolledWindow has GTK_POLICY_NEVER on the horizontal axis and GTK_POLICY_ALWAYS on the vertical axis.

The GtkText behaves as expected

The GtkPicture is shrunk down to 0x0 when the window is not tall enough.
The behavior I want is for the GtkPicture to take as much space as it needs vertically (so up to naural size), but keep within its limits horizontally.
I have set “can-shrink” to TRUE, I have set “vexpand” and “hexpand” to TRUE.

I think the problem is that GtkScrolledWindow creates a GtkViewport around my GtkBox and according the documentation:

The GtkViewport will start scrolling content only if allocated less than the child widget’s minimum size in a given orientation.

From using gtk_widget_measure I can see that my widgets minimum size is 0, which is what I want it to be because I want it to be adaptive. What I don’t understand is how I’m supposed to tell GtkViewport to not use the minimum size for vertical size allocation so my GtkPicture elements have a chance to expand. Do I need to make my own GtkViewport somehow by implementing GtkScrollable?

Some tips on how to most easily accomplish this behaviour would be highly appreciated!
If something is unclear, feel free to ask.

NOTE: This is a continuation of the previous following post, where I tried to do the same thing but everything insize a GtkTextView. I hoped that it would be easier if I split it all out into a GtkBox, but it does not seem trivial at least.

After sleeping for a few hours and working for a few hours and taking an attempt at it again, I was able to solve it.

I missed that GtkScrollable (which GtkViewport implements) has the “vscroll-policy” property that can be set to GTK_SCROLL_NATURAL. So all I had to do was to create the viewport myself instead of GtkScrolledWindow creating it for me and then set the “vscroll-policy” as mentioned.

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