如何将键盘焦点放到弹出的Gtk.Window上 [英] How to give keyboard focus to a pop-up Gtk.Window

查看:418
本文介绍了如何将键盘焦点放到弹出的Gtk.Window上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹出式窗口(使用WINDOW_POPUP类型创建),其中包含一些小部件,包括文本条目。问题是,当我点击它时,条目没有得到重点,所以我不能输入任何内容。是否有任何标志我必须设置,以允许窗口获得键盘焦点?

解决方案

您不能使用WINDOW_POPUP for gtk - 需要重点的窗口。相反,您应该使用类型为GTK_WINDOW_TOPLEVEL的GtkWindow并调用下一个函数(或方法)。
$ b $ pre $ GtkWindow * result = g_object_new(GTK_TYPE_WINDOW, type,GTK_WINDOW_TOPLEVEL,NULL);
gtk_widget_set_can_focus(result,TRUE);
gtk_window_set_decorated(GTK_WINDOW(result),FALSE);
gtk_window_set_type_hint(GTK_WINDOW(result),GDK_WINDOW_TYPE_HINT_POPUP_MENU);
gtk_window_set_transient_for(GTK_WINDOW(result),main_top_level_window);

这对我有用......不幸的是,当这个弹出窗口时,窗口列表中的图标闪烁'被销毁

I have a pop-up window (created using the WINDOW_POPUP type) which contains some widgets on it, including a text entry. The problem is that the entry doesn't get the focus when I click on it, so I can't type anything. Is there any flag I have to set to allow the window to get the keyboard focus?

解决方案

You can not use WINDOW_POPUP for gtk-windows that require the focus. Instead you should use a GtkWindow with type GTK_WINDOW_TOPLEVEL and call the next functions (or methods)

GtkWindow *result = g_object_new(GTK_TYPE_WINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
gtk_widget_set_can_focus(result, TRUE);
gtk_window_set_decorated(GTK_WINDOW(result), FALSE);
gtk_window_set_type_hint(GTK_WINDOW(result), GDK_WINDOW_TYPE_HINT_POPUP_MENU);
gtk_window_set_transient_for(GTK_WINDOW(result), main_top_level_window);

This worked for me ... unfortunately the icon in the window-list blinks short when this 'popup' is destroyed

这篇关于如何将键盘焦点放到弹出的Gtk.Window上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆