你能从小部件获得父GTK窗口吗? [英] Can you get the parent GTK window from a widget?
问题描述
我有一个自定义小部件,它需要启动一个MessageDialog,为了让我把这个消息对话框放在窗口的顶部,然后我需要访问父gtk.window。有没有办法获得父GTK窗口?谢谢
I have a custom widget and it needs to launch a MessageDialog and in order for me to put that message dialog on top of the window my widget is in then I need access to the parent gtk.window. Is there a way to get the parent GTK window? Thanks
推荐答案
GTK文档提示:
The GTK docs suggest:
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
if (gtk_widget_is_toplevel (toplevel))
{
/* Perform action on toplevel. */
}
get_toplevel将返回您所在的最上面的小部件,无论是否这是一个窗口,因此is_toplevel检查。是的,有些东西是错误的,因为上面的代码做了一个get_toplevel(),那么直接的is_toplevel()(最有可能的,get_toplevel()应该被调用别的东西)。
get_toplevel will return the topmost widget you're inside, whether or not it's a window, thus the is_toplevel check. Yeah something is mis-named since the code above does a "get_toplevel()" then an immediate "is_toplevel()" (most likely, get_toplevel() should be called something else).
这篇关于你能从小部件获得父GTK窗口吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!