GTK Dialog中的Combobox为什么点击不能打开列表?
Dialog中包含一个Combobox,设置对话框属性为modal时,鼠标点击combobox不能展开下拉列表,
如果去掉gtk_window_set_modal(GTK_WINDOW(dialog),TRUE);则点击鼠标可以展开列表。
不知是什么原因,请指点,谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
I use the function gtk_dialog_new() crate a modal dialog(for more information about dialogs, please see Gtk 2.0 reference manual), and then add a combobox widget to a sub widget of the dialog I created. the following is a source code which shows how to create a modal dialog with combobox.
我使用gtk_dialog_new() 函数创建一个模态对话框(要更多关于对话框的帮助,可以查看Gtk2.0参考手册),然后添加一个组合框控件到我创建的子控件里面.下面是一份创建带有组合框控件的模态对话框的源码.
/*
* Function:CreateSubWindow
* Description:Create a modal window
* Parameter:None
* Returns:A pointer to a modal window widget
*/
GtkWidget* CreateModalWindow()
{
GList* e_nation_items = NULL;
GtkWidget* e_nation_combo;
GtkWidget* subwindow = gtk_dialog_new();
gtk_window_set_title (GTK_WINDOW (subwindow), "this is a modal window with a combobox control");
gtk_widget_set_usize(GTK_WIDGET(subwindow), 300, 120);
gtk_window_set_modal(GTK_WINDOW(subwindow), TRUE);
g_signal_connect(G_OBJECT(subwindow), "destroy", G_CALLBACK(gtk_main_quit), subwindow);
e_nation_items = g_list_append(e_nation_items, "High");
e_nation_items = g_list_append(e_nation_items, "Middle");
e_nation_items = g_list_append(e_nation_items, "Low");
e_nation_combo = gtk_combo_new();
gtk_combo_set_popdown_strings(GTK_COMBO(e_nation_combo), e_nation_items);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(subwindow)->vbox), e_nation_combo, TRUE, TRUE, 0);
return subwindow;
}
/*
* Function:on_button_press_event
* Description: call back funtion of the button press event
* Returns: TRUE if the mouse right button be clicked, otherwise, retuns FALSE
*/
gboolean on_button_press_event(GtkWidget *widget, GdkEventButton *event)
{
if (event-> button == 1)
{
gtk_widget_show_all( CreateModalWindow() );
return TRUE;
}
return FALSE;
}
int main( int argc, char *argv[] )
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *menu_items;
gtk_init (&argc, &argv);
/* create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "GTK Radio Menu Item Test");
gtk_widget_set_usize(GTK_WIDGET(window), 500, 300);
g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
gtk_window_set_modal(GTK_WINDOW(window), TRUE);
button = gtk_button_new_with_label("click here to display a modal window with combobox control ");
g_signal_connect (G_OBJECT (button), "button_press_event",G_CALLBACK (on_button_press_event), NULL);
gtk_container_add(GTK_CONTAINER(window), button);
/* display the window */
gtk_widget_show_all (window);
gtk_main ();
return 0;
}