C Gtk3-如何获取其中小部件的索引';谁的集装箱?
我有指向位于同一容器(GtkBox)中的两个不同小部件的指针。我想使用C Gtk3-如何获取其中小部件的索引';谁的集装箱?,c,widget,containers,gtk3,C,Widget,Containers,Gtk3,我有指向位于同一容器(GtkBox)中的两个不同小部件的指针。我想使用gtk\u box\u reorder\u child(container,widgetToMove,destinationIndex)将其中一个的容器位置更改为另一个的索引: GtkWidget *widgetToMove; GtkWidget *target; // Does something like 'gtk_get_container_index' exist ? gint targetIndex = gtk_ge
gtk\u box\u reorder\u child(container,widgetToMove,destinationIndex)
将其中一个的容器位置更改为另一个的索引:
GtkWidget *widgetToMove;
GtkWidget *target;
// Does something like 'gtk_get_container_index' exist ?
gint targetIndex = gtk_get_container_index(target)
gtk_box_reorder_child (myBox,widgetToMove,targetIndex);
。。。听起来很愚蠢,但是经过15分钟的搜索后,我仍然不知道如何在它的容器中获取小部件的索引
编辑:已解决,这里是解决方案
GtkWidget *widgetToMove;
GtkWidget *target;
GValue targetIndex = G_VALUE_INIT;
g_value_init (&targetIndex, G_TYPE_INT);
gtk_container_child_get_property(myBox,target,"position",&targetIndex);
gtk_box_reorder_child (myBox,widgetToMove,g_value_get_int(&targetIndex));
回答不完整,但没有足够的代表发表评论 首先,我要注意gtkBox页面引用了一个“position”子属性,不过老实说,我不记得如何访问这样的属性 我在类似情况下所做的工作是创建一个gtkGrid而不是gtkBox,并使用gtk_grid_get_child_at()方法从索引0,0开始检查每个子级。您可以使用类似于此的for循环
for(int n=0;n<numChildren;n++)
{
gtkWidget* temp = gtk_grid_get_child_at(myGrid, n, 0);
if(temp == myWidget)
break;
}
//n now holds the index of myWidget in myGrid
for(int n=0;n您可以使用gtk\u container\u get\u children()
(),它返回Glist*
()。
然后,您可以在列表上循环,或者,例如,使用g\u list\u find()
容器小部件保存一组“子属性”,您可以使用它们进行查询。您要查找的属性称为“位置”.谢谢,这就是我要搜索的!我将为问题添加一些代码,因为child\u get\u属性
使用起来并不简单。一些容器(例如ListBox)没有“position”属性。将为您提供给定容器的可用属性。谢谢,“position”属性完成了这个技巧…我将为这个问题添加一些代码,因为它的使用并不简单。