在Glade3中,当我添加一个旋钮时,我想将其最小值和默认值设置为零。
我是通过指定" Value"旋转按钮为零,以及"值"和"最低价值"调整为零。
经过测试,我可以看到它们被设置为零,但旋转按钮上不显示零值。
我们可以在这里看到,在运行程序时,左旋钮显示其默认值(即1),但右旋钮不显示0.
如果我手动编辑glade文件以将<property name="value">0</property>
添加到旋钮并运行程序,它将正确显示。
但是,如果我修改了林间空地中的文件,这条线将被林间空地删除,零点不会显示。
无论如何将零显示为默认值(使用glade),或者这是沼地中的错误?
编辑:最小工作示例:
Glade生成的xml文件:(不起作用)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="lower">1</property>
<property name="upper">5</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment2">
<property name="upper">59</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkSpinButton" id="spinbutton1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">adjustment1</property>
<property name="value">1</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="spinbutton2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">adjustment2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
我希望这个xml文件看起来像:(有效)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="lower">1</property>
<property name="upper">5</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment2">
<property name="lower">0</property>
<property name="upper">59</property>
<property name="value">0</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkSpinButton" id="spinbutton1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">adjustment1</property>
<property name="value">1</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="spinbutton2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">adjustment2</property>
<property name="value">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
如果我手动将其更改为此文件(添加了三行),它可以正常工作并且符合预期。但是如果我在Glade中打开它,更改一些内容并保存,Glade会自动删除这三行。
要编译的C代码:
// gcc `pkg-config --cflags gtk+-3.0` mwe.c -o mwe `pkg-config --libs gtk+-3.0`
#define builderfile "mwe.glade"
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
GtkBuilder *builder;
GtkWidget *window;
gtk_init(&argc, &argv);
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, builderfile, NULL);
window = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
g_object_unref(builder);
gtk_widget_show(window);
gtk_main();
return 0;
}