当前位置: 技术问答>gtk中如何获取gtk_text_view中的输入内容?
iis7站长之家
gtk编程的一些问题
来源: 互联网 发布时间:2016-04-16
本文导语: 如何在窗口边框点鼠标右键弹出的动作中加入自己的动作?在窗口边框上点鼠标右键会出现最大化最小化之类的东西,我想加入一个about之类的东西然后弹出一个对话框,不知道怎么实现,各位大大支个招~~~ 还有一个问题,在linux下...
如何在窗口边框点鼠标右键弹出的动作中加入自己的动作?在窗口边框上点鼠标右键会出现最大化最小化之类的东西,我想加入一个about之类的东西然后弹出一个对话框,不知道怎么实现,各位大大支个招~~~
还有一个问题,在linux下如何制作程序的图标?在window下程序可以制作自己的图标,linux如何制作?
|
弹出菜单popup,类似的lz自己改改……
#include
static gint my_popup_handler(GtkWidget *widget, GdkEvent *event)
{
GtkMenu *menu;
GdkEventButton *event_button;
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
menu = GTK_MENU (widget);
if(event -> type == GDK_BUTTON_PRESS)
{
event_button = (GdkEventButton *) event;
if(event_button->button == 3)
{
gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
event_button->button, event_button->time);
return TRUE;
}
}
return FALSE;
}
int main(int argc, char* argv[])
{
GtkWidget *window;
GtkWidget *box;
GtkWidget *button;
GtkWidget *menubar;
GtkWidget *menu;
GtkWidget *editmenu;
GtkWidget *helpmenu;
GtkWidget *rootmenu;
GtkWidget *menuitem;
GtkAccelGroup *accel_group;
gtk_init(&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW(window), "弹出式菜单");
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
accel_group = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
box = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), box);
menu = gtk_menu_new();
menuitem = gtk_image_menu_item_new_from_stock
(GTK_STOCK_NEW, accel_group);
gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_image_menu_item_new_from_stock
(GTK_STOCK_OPEN, accel_group);
gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_image_menu_item_new_from_stock
(GTK_STOCK_SAVE, accel_group);
gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_image_menu_item_new_from_stock
(GTK_STOCK_SAVE_AS, accel_group);
gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
gtk_widget_show(menuitem);
menuitem = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_image_menu_item_new_from_stock
(GTK_STOCK_QUIT, accel_group);
gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
rootmenu = gtk_menu_item_new_with_label(" 文件 ");
gtk_menu_item_set_submenu (GTK_MENU_ITEM(rootmenu), menu);
menubar = gtk_menu_bar_new();
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), rootmenu);
rootmenu = gtk_menu_item_new_with_label(" 编辑 ");
editmenu = gtk_menu_new();
menuitem = gtk_image_menu_item_new_from_stock
(GTK_STOCK_CUT, accel_group);
gtk_menu_shell_append(GTK_MENU_SHELL(editmenu), menuitem);
menuitem = gtk_image_menu_item_new_from_stock
(GTK_STOCK_COPY, accel_group);
gtk_menu_shell_append(GTK_MENU_SHELL(editmenu), menuitem);
menuitem = gtk_image_menu_item_new_from_stock
(GTK_STOCK_PASTE, accel_group);
gtk_menu_shell_append(GTK_MENU_SHELL(editmenu), menuitem);
menuitem = gtk_image_menu_item_new_from_stock
(GTK_STOCK_FIND, accel_group);
gtk_menu_shell_append(GTK_MENU_SHELL(editmenu), menuitem);
gtk_widget_show(rootmenu);
gtk_menu_item_set_submenu (GTK_MENU_ITEM(menubar), rootmenu);
rootmenu = gtk_menu_item_new_with_label(" 帮助 ");
helpmenu = gtk_menu_new();
menuitem = gtk_image_menu_item_new_from_stock
(GTK_STOCK_HELP, accel_group);
gtk_menu_shell_append(GTK_MENU_SHELL(editmenu), menuitem);
menuitem = gtk_menu_item_new_with_label(" 关于...");
gtk_menu_shell_append(GTK_MENU_SHELL(helpmenu),menuitem);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(rootmenu), helpmenu);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), rootmenu);
gtk_box_pack_start(GTK_BOX(box), menubar, FALSE, FALSE, 5);
button = gtk_button_new_with_label("单击右键弹出菜单");
g_signal_connect_swapped(GTK_OBJECT(button),
"button_press_event",
G_CALLBACK(my_popup_handler), GTK_OBJECT(menu));
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 5);
gtk_widget_show_all(window);
gtk_main();
return FALSE;
}
|
那个在 GTK+ 2.0编程范例 http://www.china-pub.com/8419
看到过 鼠标右键弹出自定义菜单
不过没实践 ,记不清了
看到过 鼠标右键弹出自定义菜单
不过没实践 ,记不清了
|
接分来也
|
图标是desktop文件。
|
gtk提供about的,你用glade-2 做个demo试试。
|
楼上方法即可。。
其实就是一个popmenu
其实就是一个popmenu
|
哈哈。。。