ezpresso
ezpresso

Reputation: 8126

How to make widget to occupy all the available space in Gtk.HBox

I am implementing a custom Gtk# widget which is based on Gtk.EventBox. When I am inserting it into the HBox or VBox it occupies the exact size that is returned by OnSizeRequested method.

How can I make my widget to occupy all the space given to it by the parent box, window or the widget? Just like HBox does.

Upvotes: 0

Views: 2472

Answers (2)

Micah Carrick
Micah Carrick

Reputation: 10197

There is a slight different between the preferred way to do packing in GTK+2 vs GTK+3. With GTK+ you would typically use expand and fill properties of a GtkBox to control how space is allocated. With GTK+3 they are suggesting the user of vertical-expand, horizontal-expand, vertical-fill, horizontal-fill.

A good way to understand how packing works is to play with the fill and expand properties with Glade so you can see the effects in real time. An old tutorial (slightly out of date) shows some screenshots of different packing properties: How_Packing_Effects_the_Layout

As you are developing a widget it is more likely that users of your widget will determine how it should be packed in a larger UI. However, if you're widget is a composite widget (built from other widgets) then you will need to pack the other widgets properly.

Upvotes: 2

mkestner
mkestner

Reputation: 246

PackStart and PackEnd have a fill parameter to specify items that should expand to fill the box. You probably want PackStart(widget, true, true, 0);

Upvotes: 0

Related Questions