简体   繁体   English

gtkmm:将容器小部件(Box)中的元素堆叠在一起

[英]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.我使用了 ButtonBox,并在里面放了一些切换按钮、颜色按钮和一个普通按钮。

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.如果我不想要第二件事,我可以使用set_valign使工具栏向右缩小。

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.我尝试在颜色按钮后添加空的 Gtk::Box 并允许它展开,这将最右边的按钮保留在右侧,但它仍然在按钮之间留下边距,无论我尝试的pack_startpack_end参数是什么 - 有两个可选的布尔值参数,但它们似乎都没有做任何事情。

Here is how it looks normally:这是它的正常外观:

问题

Here is how it looks with empty box:这是它在空盒子中的样子:

问题

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?那么我应该怎么做才能删除按钮之间的边距,有没有更好的方法让一些按钮在右边,一些在左边?

ButtonBox will always have space between buttons. ButtonBox 将始终在按钮之间留有空间。 If you want the buttons without space between, use a regular Box.如果您希望按钮之间没有空格,请使用常规 Box。

Otherwise you did the right thing.否则你做对了。 Use a Box to move the right button to the edge.使用 Box 将右键移动到边缘。 Sometimes you can achieve the same affect by using pack_start and pack_end to different buttons, all within the same Box.有时您可以通过对不同的按钮使用pack_startpack_end来实现相同的pack_end ,所有按钮都在同一个 Box 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM