寻找GtkWidget的孩子 [英] Finding children of a GtkWidget

查看:119
本文介绍了寻找GtkWidget的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够以编程方式探索GTK GUI的结构。我有GtkWidget,我想找到那个小部件的任何孩子。现在我知道GtkContainer有一个可以找到孩子的函数,而且GtkContainer是从GtkWidget派生的。



有没有我可以检查一个小部件是否是GtkContainer,然后执行投?如果没有,有没有其他方法可以发现GtkWidget是我所拥有的孩子的?

是的,那里有是每个GObject类型的宏来检查一个对象是否是这种类型:

  if(GTK_IS_CONTAINER(widget)){
GList * children = gtk_container_get_children(GTK_CONTAINER(widget));
...
}

如果小部件是 GtkBin 它只有一个孩子。在这种情况下,下面比处理 GList 更简单:

  if(GTK_IS_BIN(widget)){
GtkWidget * child = gtk_bin_get_child(GTK_BIN(widget));
...
}


I need to be able to explore a GTK GUI's structure programmatically. I have the GtkWidget and I want to find any children of that widget. Now I know that GtkContainer's have a function to find children and that GtkContainer is derived from GtkWidget.

Is there anyway I can check if a widget is a GtkContainer and then perform the cast? If not, is there any other way I can discover the GtkWidget's that are children of the one I have?

解决方案

Yes, there are macros for every GObject type to check whether an object is of that type:

if(GTK_IS_CONTAINER(widget)) {
    GList *children = gtk_container_get_children(GTK_CONTAINER(widget));
    ...
}

If the widget is a GtkBin it has only one child. In that case, the following is simpler than dealing with a GList:

if(GTK_IS_BIN(widget)) {
    GtkWidget *child = gtk_bin_get_child(GTK_BIN(widget));
    ...
}

这篇关于寻找GtkWidget的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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