开发者

gtk composite widget focus

I created a composite widget with webkit_webview widget stored in scrollwed window with a gtkvbox base widget. How do make to so the base gtkvbox widget is in focus whenever a开发者_运维知识库ny of the contained widgets have focus? Specifically, I am trying to add accelerator that should only be active when the composite widget is in focus. To determine if the composite widget is in focus I call gtk_widget_get_focused(), and then traverse up the widget parents to to the fill find the base widget . It seems like there should be a better way.


Only one widget at a time can have the global input focus, which is the focus that the user sees on the screen, and where the keystrokes appear. If gtk_widget_has_focus(widget) returns TRUE then widget has the global input focus. You can't have the webview and the vbox have the global input focus at the same time.

What you can do is call gtk_container_get_focus_child() on the composite widget's parent, and if the return value is your composite widget, then the focus is somewhere within the composite widget.

Or you can connect to the "focus-in-event" and "focus-out-event" signals on the composite widget. I'm fairly sure these will notify you when one of the contained widgets gains or loses the focus. (Remember to call gdk_window_set_events(widget->window, gdk_window_get_events(widget->window) | GDK_FOCUS_CHANGE_MASK) on your widget first, as explained in the GTK docs.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜