开发者

arranging icons in gtk toolbar

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 开发者_StackOverflow= 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:

arranging icons in gtk toolbar


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜