我想使用 GtkBuilder ui 文件来声明一个 3 行 2 列的 GtkGrid。 ui 文件应该可与 gtk4-rs ( https://github.com/gtk-rs/gtk4-rs ) 一起使用。最初我使用 Glade 来获取 ui 文件的第一个草图,但不幸的是 gtk4-rs 确实无法加载它。因此,我将其精简,直到我可以启动我的应用程序。如何将元素分配到列中,以便 gtk4-rs 仍然能够加载它?
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.4"/>
<object class="GtkApplicationWindow" id="window">
<child>
<object class="GtkGrid">
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Label1</property>
</object>
</child>
<child>
<object class="GtkButton" id="src_button">
<property name="label" translatable="yes">Source</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Label2</property>
</object>
</child>
<child>
<object class="GtkButton" id="trg_button">
<property name="label" translatable="yes">Target</property>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Start</property>
<property name="receives-default">True</property>
</object>
</child>
</object>
</child>
</object>
</interface>
在哪里可以找到 GtkGrind 或其他 Gtk4 对象的 DTD?
最佳答案
我不知道你是否发现了,但可能有人会看到这篇文章来寻找答案。解决方案是使用<layout>
里面的 child <object>
。在您的示例中它将是:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.4"/>
<object class="GtkApplicationWindow" id="window">
<child>
<object class="GtkGrid">
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Label1</property>
<layout>
<property name="row">0</property>
<property name="column">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="src_button">
<property name="label" translatable="yes">Source</property>
<layout>
<property name="row">0</property>
<property name="column">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Label2</property>
<layout>
<property name="row">1</property>
<property name="column">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="trg_button">
<property name="label" translatable="yes">Target</property>
<layout>
<property name="row">1</property>
<property name="column">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Start</property>
<property name="receives-default">True</property>
<layout>
<property name="row">3</property>
<property name="column">0</property>
</layout>
</object>
</child>
</object>
</child>
</object>
</interface>
关于rust - GTK4 : How to specify rows and columns of a GtkGrid object within a GtkBuilder ui file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65471089/