Frame minimum size

I have a frame which is packed PACK_EXPAND_WIDGET inside its parent (a vertical box). Its upper and lower border widths are zero, and it has no content (it is just to be used as padding, perhaps with a pretty-coloured background). I want to set its minimum height to zero (so it becomes completely invisible until its parent grows to a height where it is needed). So I use set_size_request(-1, 0). But that does not work: the absolute minimum height seems to be 4px.

How can I achieve this? There is a horrid workaround involving on_size_allocate and much other messiness, and this idea seemed so simple.

I am actually using gtkmm (whatever version comes with ubuntu 18.04).

This is not possible with GTK3: for historical and backward compatibility reasons, widgets have a minimum size of 1x1 and it’s enforced inside GtkWidget itself.

This is likely caused by the CSS box applying some margin/padding.

Use gtk_widget_set_child_visible() when you don’t want the widget to contribute to the layout.

[ebassi] ebassi https://discourse.gnome.org/u/ebassi Emmanuele Bassi
https://discourse.gnome.org/u/ebassi Foundation Staff
February 10

clerew:

I want to set its minimum height to zero (so it becomes completely invisible
until its parent grows to a height where it is needed)

This is not possible with GTK3: for historical and backward compatibility
reasons, widgets have a minimum size of 1x1 and it’s enforced inside GtkWidget
itself.

clerew:

But that does not work: the absolute minimum height seems to be 4px.

This is likely caused by the CSS box applying some margin/padding.

Yes, I spotted that eventually and changed the css script.

But, contrary to what you said above, it DID then allow the height to reduce to
zero (seemingly the parent’s pack comment which allowed the Frame to expand to
fill the available space also allowed it to shrink to zero.

BUT any attempt to use padding.set_size_request(-1, 0); did leave the minimum at
1px, so I removed all such calls, and it is now working like a charm.

clerew:

How can I achieve this?

Use |gtk_widget_set_child_visible()|
https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-set-child-visible
when you don’t want the widget to contribute to the layout.

Yes, but that was the sort of complication I was trying to avoid, and even if
the Frame was hidden, it still insisted on leaving an empty space of the minimum
size where it had been until you did a window->resize(1,1).

Anyway, as I said, it is now working as I eanted.