如何使用GTK + C ++在子菜单中插入对话框?

时间:2016-06-12 14:00:34

标签: gtk gtk3 gtkmm gtk2

我是GTK +(c ++)的新手。我使用这个版本的gtk: gtk + bundle_3.4.2-20130513_win64 我设计了一个带有两个菜单的菜单(帮助):OpenCV和GTK。

enter image description here

我想用GTK + C ++在子菜单中插入任何一个对话框。与此类似:

enter image description here

实际上我的最终结果是:

enter image description here

但我不能。你会建议如何解决这个任务的想法?或者我可以在互联网上的哪些资源上找到帮助?

这是我的c ++代码:

GtkWidget *vbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, FALSE);
gtk_container_set_border_width(GTK_CONTAINER(win), 10);
gtk_table_attach_defaults(GTK_TABLE(table), vbox2, 1, 2, 0, 1);

GtkWidget *menubar2 = gtk_menu_bar_new();
GtkWidget *helpMenu = gtk_menu_new();
GtkAccelGroup *accel_group2 = NULL;
accel_group2 = gtk_accel_group_new();

gtk_window_add_accel_group(GTK_WINDOW(win), accel_group2);

GtkWidget *helpMi = gtk_menu_item_new_with_mnemonic("_Help");

//opencvMi
GtkWidget *imageOpenCV, *opencvMi;
imageOpenCV = gtk_image_new_from_file("E:/Works for Gov Project/DOC    /GUI/logogui1/opencv.png");
opencvMi = gtk_image_menu_item_new_with_mnemonic("OpenCV");
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(opencvMi),     GTK_WIDGET(imageOpenCV));
gtk_widget_show(opencvMi);    

GtkWidget *linkbutton_opencv =     gtk_menu_item_new_with_label("http://www.opencv.org");

//gtkMi
GtkWidget *imageGTK,*gtkMi;
imageGTK = gtk_image_new_from_file("E:/Works for Gov Project/DOC    /GUI/logogui1/gtk.png");
gtkMi = gtk_image_menu_item_new_with_mnemonic("GTK+");
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(gtkMi),     GTK_WIDGET(imageGTK));
gtk_widget_show(gtkMi);

GtkWidget *linkbutton_gtk =     gtk_menu_item_new_with_label("http://www.gtk.org/");


GtkWidget *imprMenu2 = gtk_menu_new();

GtkWidget *imprMenu3 = gtk_menu_new();

gtk_menu_item_set_submenu(GTK_MENU_ITEM(helpMi), helpMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(helpMenu), opencvMi);
gtk_menu_shell_append(GTK_MENU_SHELL(helpMenu), gtkMi);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar2), helpMi);

gtk_menu_item_set_submenu(GTK_MENU_ITEM(opencvMi), imprMenu2);
gtk_menu_shell_append(GTK_MENU_SHELL(imprMenu2), linkbutton_opencv);

gtk_menu_item_set_submenu(GTK_MENU_ITEM(gtkMi), imprMenu3);
gtk_menu_shell_append(GTK_MENU_SHELL(imprMenu3), linkbutton_gtk);


gtk_box_pack_start(GTK_BOX(vbox2), menubar2, FALSE, FALSE, 0);

这是对话框的代码( GtkAboutDialog ):

http://zetcode.com/gui/gtk2/gtkdialogs/

0 个答案:

没有答案