0
我正在使用帶有Glade XML文件的GtkBuilder
。我想將窗口大小改爲全屏,而不使用gtk_window_fullscreen
方法(因爲這需要在沒有窗口管理器的情況下工作),所以我得到屏幕尺寸並製作窗口大小。當我以編程方式創建小部件時,這用於工作,但是當我切換到Glade/GtkBuilder
時,該窗口與Glade編輯器中的小尺寸相同。我需要用GtkBuilder
做些什麼嗎?下面的代碼:使用GtkBuilder時無法更改GtkWindow大小
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
gtk_init(&argc, &argv);
GtkBuilder *builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "dm.ui", NULL);
GObject *window = gtk_builder_get_object(builder, "window");
// Make full screen
GdkScreen *screen = gdk_screen_get_default();
gint height = gdk_screen_get_height(screen);
gint width = gdk_screen_get_width(screen);
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_main();
}
這裏的XML文件,dm.ui:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.2 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkWindow" id="window">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLayout" id="main_layout">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="user_text_field">
<property name="width_request">162</property>
<property name="height_request">31</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_right">42</property>
</object>
<packing>
<property name="x">175</property>
<property name="y">73</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="user_label">
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Username</property>
</object>
<packing>
<property name="x">71</property>
<property name="y">46</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="password_label">
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Password</property>
</object>
<packing>
<property name="x">72</property>
<property name="y">103</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="password_text_field">
<property name="width_request">162</property>
<property name="height_request">31</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="x">177</property>
<property name="y">129</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
工作,謝謝。 – gsingh2011
不客氣 – luciomrx