GtkBuilder没有实现widgets吗?
我有一个简单的 Glade 文件,包含在 C 源代码中。以下是有趣的部分:
int main(int argc, char *argv[]) {
GtkBuilder *builder;
gtk_init(&argc, &argv);
gdk_gl_init(&argc, &argv);
// ... some OpenGL specific initializations
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "gui.ui", NULL);
gtk_builder_connect_signals(builder, NULL);
window = GTK_WIDGET(gtk_builder_get_object(builder, "main_window"));
drawingArea = GTK_wIDGET(gtk_builder_get_object(builder, "drawing_area"));
gtk_container_set_reallocate_redraws(GTK_CONTAINER(window), TRUE);
gtk_widget_set_gl_capability(drawingArea, glConfig, NULL, TRUE, GDK_GL_RGBA_TYPE);
// ...
}
如果我编译此代码,我会收到此警告:
gtk_widget_set_gl_capability: assertion `!gtk_widget_get_realized (widget)' failed
如果我现在使用 LibGlade 而不是 GtkBuilder 与此代码(我保存了空地文件以与 Libglade 兼容):
int main(int argc, char *argv[]) {
GladeXML *xml;
gtk_init(&argc, &argv);
gdk_gl_init(&argc, &argv);
// ... some OpenGL specific initializations
xml = glade_xml_new("gui.glade", NULL, NULL);
glade_xml_signal_autoconnect(xml);
window = glade_xml_get_widget(xml, "main_window");
drawingArea = glade_xml_get_widget(xml, "drawing_area");
gtk_container_set_reallocate_redraws(GTK_CONTAINER(window), TRUE);
gtk_widget_set_gl_capability(drawingArea, glConfig, NULL, TRUE, GDK_GL_RGBA_TYPE);
// ...
}
一切正常,不会出现错误。我已经尝试了几种方法来强制在 GtkBuilder 版本中实现绘图区域,但没有任何效果。我在这里忘记了什么魔术吗?
I have a simple Glade-file included in a C source. Here are the interesting parts:
int main(int argc, char *argv[]) {
GtkBuilder *builder;
gtk_init(&argc, &argv);
gdk_gl_init(&argc, &argv);
// ... some OpenGL specific initializations
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "gui.ui", NULL);
gtk_builder_connect_signals(builder, NULL);
window = GTK_WIDGET(gtk_builder_get_object(builder, "main_window"));
drawingArea = GTK_wIDGET(gtk_builder_get_object(builder, "drawing_area"));
gtk_container_set_reallocate_redraws(GTK_CONTAINER(window), TRUE);
gtk_widget_set_gl_capability(drawingArea, glConfig, NULL, TRUE, GDK_GL_RGBA_TYPE);
// ...
}
If I compile this, I get this warning:
gtk_widget_set_gl_capability: assertion `!gtk_widget_get_realized (widget)' failed
If I now use LibGlade instead of the GtkBuilder with this code (I saved the glade file to be compatible with Libglade):
int main(int argc, char *argv[]) {
GladeXML *xml;
gtk_init(&argc, &argv);
gdk_gl_init(&argc, &argv);
// ... some OpenGL specific initializations
xml = glade_xml_new("gui.glade", NULL, NULL);
glade_xml_signal_autoconnect(xml);
window = glade_xml_get_widget(xml, "main_window");
drawingArea = glade_xml_get_widget(xml, "drawing_area");
gtk_container_set_reallocate_redraws(GTK_CONTAINER(window), TRUE);
gtk_widget_set_gl_capability(drawingArea, glConfig, NULL, TRUE, GDK_GL_RGBA_TYPE);
// ...
}
All works fine and no error appear. I've tried several things to force the realize the drawing_area in the GtkBuilder version but nothing worked. Is there some magic trick that I forgot here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将顶部窗口的 Visible 属性设置为 False。
过去几周我遇到了完全相同的问题。我从glade2 转换为glade3 并使用gtkglext 的glade xml 文件不会接受gtk_widget_set_gl_capability 调用。在我阅读这篇文章并与功能文件进行比较(感谢 Jose Commins )后,我意识到顶部窗口上的可见属性设置为 True。将其更改为 False,一切正常。由于旧的glade2 文件中的所有顶部窗口都设置为True,因此这一定是默认值。较新的软件将其设置为 False。构建器必须在创建顶部窗口时对其进行初始化并将其标记为可见,这与等待显式调用创建函数的旧 C 代码做法相反。
Set the Visible property of the top Window to
False
.I have had the exact same problem for the last couple of weeks. A glade xml file that I converted from glade2 to glade3 that used gtkglext just would not accept the gtk_widget_set_gl_capability call. After I read this post and did a comparison with a functioning file (thanks to Jose Commins ) did I realize that the visible property on the top window was set to True. Change it to False, everything works. Since all the top windows in the old glade2 file were set to True, that must have been the default. The newer software sets it to False. Builder must initialize the top window when it is created and labeled as visible in contrast to the old C code practice of waiting until the create functions were explicitly called.