您可以从小部件中获取父 GTK 窗口吗? [英] Can you get the parent GTK window from a widget?

查看:30
本文介绍了您可以从小部件中获取父 GTK 窗口吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义小部件,它需要启动一个 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 文档建议:

   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屋!

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