Search code examples
gtk3glade

GTK3: Making a container aligned to bottom, filling horizontal space but not vertical


all.

I am writing an app in C with GTK3 and using Glade to build the UI. What I am trying to do is making a container that will stay on the bottom of the frame, filling the horizontal space but not vertical. I will place a few buttons there and don't want them loose in the frame. Right now I just have enough code to show the window to see how it looks in runtime, focusing just on UI.

What I have tried so far:

  • GtkBox: would be perfect if I could adjust its height so I have free space above it, for another container. But it seems to take whatever free space is left (that is, the whole screen).
  • GtkPaned: would be perfect if I could prevent it from being resized in runtime and hide the handle. But, well, this is the purpose of this widget, so it doesn't seem to be possible.
  • GtkGrid: same thing as GtkBox.

For those who already worked with Borland C++ Builder or Delphi, it is the functionality of a "Panel" I'm trying to repeat. That is, you drop the container in the frame, align it to bottom (which makes it fill the horizontal space) and then you adjust the height in design time.

Any ideas? If you need more information, just let me know.


*EDIT: Alexander, this is when I try to expand on your comment, that is, using more than 1 button and container inside a container (see top right of Glade for the hierarchy). When all buttons have Expand "Off", which works for 1 button, and when it is "On" (then I don't get to adjust the height anymore).

"No" to all buttons "Yes" to all buttons


Solution

    • The simpliest solution: take GtkBox and use gtk_box_pack_end.
    • Another way is to control container align and expand behaviour (use gtk_widget_set_halign/gtk_widget_set_valign and gtk_widget_set_hexpand/gtk_widget_set_vexpand on the container itself)

    Edit: didn't notice you are using glade. Create a gtkbox, add a child and change child's pack typeCreate a gtkbox, add a child and change child's pack type


    Also notice: if you want to add container near another container, you should pack both containers in another container.