GTK+菜单栏看起来很糟糕
我正在按照此处的说明编写 Gtk+ 菜单栏。
当将菜单栏打包到 VBox 上时,
// "FALSE, TRUE" and "FALSE, FALSE" actually makes no difference
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar,
TRUE, FALSE, 0);
看起来很糟糕,如下所示:
当我更改为:
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar,
TRUE, TRUE, 0);
它看起来像:
那么,如何让工具栏分配更小的空间呢?
I'm writing a Gtk+ menu bar following the instruction here.
When packing the bar onto a VBox with
// "FALSE, TRUE" and "FALSE, FALSE" actually makes no difference
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar,
TRUE, FALSE, 0);
the menu bar looks terrible, like this:
And when I changed to:
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar,
TRUE, TRUE, 0);
it looks like:
So, how to make the toolbar get a smaller space allocated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题,你想要:
因此,您的其他小部件(即菜单栏下方的按钮栏)的打包模式开始发挥作用(为了清楚起见,我将它们称为
button_hbox
和 < code>menu_bar,因为两者都可以称为“工具栏”)。了解传递给 gtk_box_pack_start() 在这里至关重要:
如果小部件在计算布局后应消耗其容器中剩余的空白空间,则第一个
expand
为TRUE
。以这种方式打包的小部件平等地竞争剩余空间。如果小部件应该填充它所占用的布局空间而不是居中(出现浅灰色填充),则第二个
fill
为TRUE
。这个想法是,您在
main_vbox
中有一个(或多个,但现在我们只使用一个)主小部件,并且该小部件包含expand
和fill
设置为TRUE
。它周围的卫星小部件包含设置为FALSE
的expand
和设置为TRUE
的fill
。例如:在您的情况下,由于您不希望
menu_bar
填充可用空间,因此button_hbox
应该这样做:If I understand your question correctly, you want to:
Therefore, the packing mode of your other widget (namely the button bar below your menu bar) comes into play (for clarity, I'll refer to them as
button_hbox
andmenu_bar
, respectively, since both can qualify as "toolbars").Understanding the boolean layout arguments passed to gtk_box_pack_start() is paramount here:
The first one,
expand
, isTRUE
if the widget should consume the empty space left in its container after layout is computed. Widgets packed this way compete equally for the remaining space.The second one,
fill
, isTRUE
if the widget should fill the layout space it consumes instead of being centered within it (there comes the light gray padding).The idea is that you have one (or more, but let's stick to one for now) main widget in
main_vbox
, and that widget is packed with bothexpand
andfill
set toTRUE
. The satellite widgets around it are packed withexpand
set toFALSE
andfill
set toTRUE
. For instance:In your case, since you don't want
menu_bar
to fill the available space,button_hbox
should do so: