在 gtk 工具栏中排列图标

发布于 2024-10-07 08:39:58 字数 776 浏览 2 评论 0原文

我正在尝试创建一个包含一堆项目的 GTK 工具栏。我的问题是我无法将它们均匀地分开。所有图标都聚集在栏的左侧。我怎样才能让它们散开?出于性能原因,我想避免使用 hbox 等其他小部件。这是我编写的代码:

GtkWidget* navbar = gtk_toolbar_new();
gtk_toolbar_set_style(GTK_TOOLBAR(navbar), GTK_TOOLBAR_ICONS);
gtk_toolbar_set_icon_size(GTK_TOOLBAR(navbar), GTK_ICON_SIZE_SMALL_TOOLBAR);

GtkToolItem* open = gtk_tool_button_new_from_stock(GTK_STOCK_JUMP_TO);
gtk_toolbar_insert(GTK_TOOLBAR(navbar), open, 0);

GtkToolItem* play = gtk_tool_button_new_from_stock(GTK_STOCK_MEDIA_PLAY);
gtk_toolbar_insert(GTK_TOOLBAR(navbar), play, 1);  

GtkToolItem* pause = gtk_tool_button_new_from_stock(GTK_STOCK_MEDIA_PAUSE);
gtk_toolbar_insert(GTK_TOOLBAR(navbar), pause, 2);

这是我得到的安排:

alt text

I am trying to create a GTK toolbar with a bunch of items. My probelem is that I have not been able to space them out evenly. All icons are bunched together on the left of the bar. How do I get them to spread out? I would like to avoid using additional widgets like hbox, etc for performance reasons. Here's the code I have written:

GtkWidget* navbar = gtk_toolbar_new();
gtk_toolbar_set_style(GTK_TOOLBAR(navbar), GTK_TOOLBAR_ICONS);
gtk_toolbar_set_icon_size(GTK_TOOLBAR(navbar), GTK_ICON_SIZE_SMALL_TOOLBAR);

GtkToolItem* open = gtk_tool_button_new_from_stock(GTK_STOCK_JUMP_TO);
gtk_toolbar_insert(GTK_TOOLBAR(navbar), open, 0);

GtkToolItem* play = gtk_tool_button_new_from_stock(GTK_STOCK_MEDIA_PLAY);
gtk_toolbar_insert(GTK_TOOLBAR(navbar), play, 1);  

GtkToolItem* pause = gtk_tool_button_new_from_stock(GTK_STOCK_MEDIA_PAUSE);
gtk_toolbar_insert(GTK_TOOLBAR(navbar), pause, 2);

And here is the arrangement I get:

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无需解释 2024-10-14 08:39:58

您可以在每个项目之间添加一个 GtkSeparatorToolItem ;引用 GTK 文档,

如果属性 expandTRUE 并且属性 drawFALSE,则为 GtkSeparatorToolItem< /code> 将充当“弹簧”,将其他项目强制到工具栏的末端。


听听放松怎么说,但不要这样做!甚至不要将它们放在工具栏的中央。 GTK 小部件设计用于各种不同的尺寸、分辨率、桌面主题、语言和配置。你设计应用程序如何工作,GTK 设计它的外观(我向你保证,GTK 团队比你更多地考虑可用性。)用户期望工具按钮位于某个位置。

You can add a GtkSeparatorToolItem in between each item; quoting from the GTK documentation,

If the property expand is TRUE and the property draw is FALSE, a GtkSeparatorToolItem will act as a "spring" that forces other items to the ends of the toolbar.

Listen to what unwind says though, and don't do it! Don't even place them in the center of the toolbar. GTK widgets are designed to work in all kinds of different sizes, resolutions, desktop themes, languages, and configurations. You design how the application works, GTK designs how it looks (and I assure you, the GTK team has thought more about usability than you have.) Users expect tool buttons to be in a certain place.

ゝ偶尔ゞ 2024-10-14 08:39:58

我确实相信这是设计使然;工具栏应该紧密排列,以使其更可用。在我个人看来,如果示例图像中的六个按钮均匀分布在整个水平空间上,看起来会更糟。

也就是说,您可以尝试使用 gtk_tool_item_set_expand() 将项目添加到工具栏之前。

I do believe that this is by design; toolbars are supposed to be packed tightly, to make them more usable. In my personal opinion, the six buttons in the example image would look way worse if spread out evenly over the full horizontal space.

That said, you can try using gtk_tool_item_set_expand() on your items before adding them to the toolbar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文