0

我创建了用C.

我添加了工具栏:

在此处输入图像描述

这是相关的代码片段:

GtkWidget *toolbar;
GtkToolItem *new;
GtkToolItem *open;
GtkToolItem *save;
GtkToolItem *sep;
GtkToolItem *exit;





...
toolbar = gtk_toolbar_new();    
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);

gtk_container_set_border_width(GTK_CONTAINER(toolbar), 2);

new = gtk_tool_button_new_from_stock(GTK_STOCK_NEW);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), new, -1);

open = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), open, -1);

save = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), save, -1);

sep = gtk_separator_tool_item_new();
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), sep, -1); 

exit = gtk_tool_button_new_from_stock(GTK_STOCK_QUIT);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), exit, -1); 


....



gtk_widget_show_all (window);

问题是,当我按下退出/打开时,如何将侦听器(回调)添加到工具栏...

对于单个按钮,我有类似的东西:

g_signal_connect (G_OBJECT (_button), "clicked", G_CALLBACK (on_button_clicked), NULL);

void on_button_clicked(){...}

我知道如何做到这一点,gtk_ui_manager但它太复杂了。

请帮忙

4

1 回答 1

1

是在主窗口吗?

g_signal_connect(G_OBJECT(exit), "clicked", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

更多信息:http: //zetcode.com/tutorials/gtktutorial/menusandtoolbars/

于 2012-12-16T12:30:58.880 回答