添加小部件时更新 Gtk 容器
我有一些代码,在 UI 最初构建后,用一些数据中的新小部件填充 GtkVBox。
所以有一些代码稍后运行,看起来像这样:
gchar* str = "something or other";
ascii_labels [i] = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (ascii_labels [i]), str);
ascii_event_boxes [i] = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (ascii_event_boxes [i]),
ascii_labels [i]);
gtk_box_pack_start (GTK_BOX (ascii_box),
ascii_event_boxes [i],
FALSE, FALSE, 0);
在某个循环中。稍后我必须
gtk_widget_show_all (ascii_box);
设置可见性。这似乎有效,因为当我使用 GtkParasite 运行生成的应用程序时,我可以看到小部件正确嵌套在小部件树中,并且它们被设置为可见。
不幸的是,它们实际上并没有出现在应用程序的窗口中!我认为我错过了某种“请更新自己”调用的原因是,如果我从 GtkParasite 工具切换其中一个小部件的可见性,所有其他丢失的小部件都会神奇地出现!
谁能告诉我我错过了什么?
I've got some code which populates a GtkVBox with new widgets from some data, after the UI is initially built.
So there's some code which runs later looking something like this:
gchar* str = "something or other";
ascii_labels [i] = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (ascii_labels [i]), str);
ascii_event_boxes [i] = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (ascii_event_boxes [i]),
ascii_labels [i]);
gtk_box_pack_start (GTK_BOX (ascii_box),
ascii_event_boxes [i],
FALSE, FALSE, 0);
in some loop. A bit later I have
gtk_widget_show_all (ascii_box);
to set visibility. This seems to work, in that when I run the resulting application with GtkParasite, I can see the widgets nested correctly in the Widget Tree and they are set to be visible.
Unfortunately, they don't actually appear in the application's window! The reason I think I'm missing some sort of "update yourself please" call is that if I toggle the visibility of one of those widgets from the GtkParasite tool, all the other widgets that were missing magically appear!
Can anyone tell me what I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
包装看起来不错,但我们需要知道
ascii_labels
包含什么以及它是如何定义的。问题不在于可见性,因为gtk_widget_show_all
会为您解决这个问题。The packing looks good, but what we need here is to know what
ascii_labels
contains, and how it's defined. The problem is not visibility, asgtk_widget_show_all
takes care of that for you.