mame98 mame98 - 1 year ago 63
C Question

GtkContainer/GtkWidget maximum width

I am trying to write an application that contains a GtkBox (Horizontal) where I add a dynamic number of buttons (with labels) depending on various conditions. Now
I want to prevent the GtkBox to grow more than (for example) 600px. The button labels can be ellipsized.

So my question is, is there any common way to solve this problem? If not, I think i would have to create a new Container Class that will watch its size.

I am using the C API for GTK (


Answer Source

There is no simple way to limit the size of a widget, at least as far as I can tell. What you can do is attach to the size-allocate signal and call set_size_request when received.

Since size requests are only requests, not commands, depending on the circumstances you may not be able to shrink the widget as much as you would like, but this should be rare.