问题描述
我正在尝试将GtkImage添加到我的主窗口* .ui文件中,该文件是使用GNOME Builder项目模板制作的.
I am trying to add a GtkImage to my main window *.ui file, which was made using the GNOME Builder project template.
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.20"/>
<template class="PodiumWindow" parent="GtkApplicationWindow">
<property name="default-width">600</property>
<property name="default-height">300</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="headerBar">
<property name="visible">True</property>
<property name="show-close-button">True</property>
<property name="title">Podium</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon-name">open-menu-symbolic</property>
<property name="icon-size">1</property>
</object>
<object class="GtkLabel" id="label">
<property name="label">Ready your pencils!</property>
<property name="visible">True</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/>
</attributes>
</object>
</child>
</template>
</interface>
但是图像未出现在窗口中:
But the image does not appear in the window:
我与GTK +检查器(Ctrl + Shift + D)进行了检查,但在层次结构中看不到GtkImage.有人知道我在想什么吗?
I checked with GTK+ Inspector (Ctrl+Shift+D) and could not see the GtkImage in the hierachy. Anyone knows what I am missing?
推荐答案
GtkWindow
是GtkBin
的子类,这意味着它一次只能生一个孩子.
GtkWindow
is a subclass of GtkBin
, which means it can only have one child at a time.
因此图像首先被添加,但是在添加标签时再次被移除.
So the image is added first, but removed again when adding the label.
要解决您的问题,您需要添加一个中间容器(例如GtkGrid
或GtkBox
).
To fix your issue, you need to add an intermediate container (like GtkGrid
or GtkBox
).
这篇关于我在主窗口UI文件中添加了gtk小部件,但未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!