添加小部件时更新 Gtk 容器

发布于 2024-12-11 21:34:33 字数 792 浏览 0 评论 0原文

我有一些代码,在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半衬遮猫 2024-12-18 21:34:33

包装看起来不错,但我们需要知道 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, as gtk_widget_show_all takes care of that for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文