Search code examples
c++user-interfacegtk3gtkmmgtkmm3

gtkmm: stack together elements in the container widget (Box)


I want to create some kind of toolbar, consisting of buttons. I used ButtonBox, and put inside some toggle buttons, color button and one regular button.

I want to accomplish two things:

  1. Make buttons stick together despite window width, without margin between them.
  2. Have rightmost button on the right of the window, and other buttons on the left.

If I didn't wanted second thing, I could just use set_valign so that toolbar would shrink to the right.

I tried adding empty Gtk::Box after color button and allowing it to expand, and this keeps rightmost button on the right, but it still leaves margins between buttons, no matter what parameters for pack_start and pack_end I try - there is two optional boolean parameters, but neither of them seem to do anything.

Here is how it looks normally:

Issue

Here is how it looks with empty box:

Issue

So what should I do to remove margin between buttons, and is there a better way to keep some buttons on the right, and some on the left?


Solution

  • ButtonBox will always have space between buttons. If you want the buttons without space between, use a regular Box.

    Otherwise you did the right thing. Use a Box to move the right button to the edge. Sometimes you can achieve the same affect by using pack_start and pack_end to different buttons, all within the same Box.