2014-05-08 46 views
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> 

回答

1

您可以嘗試使用

void gtk_widget_set_size_request(GtkWidget *widget, gint width, gint height); 

,或者您可以使用格萊德調整「默認的GtkWindow性質寬度「和」默認高度「,而不是硬編碼它。 讓我知道結果。 p.s:這就是爲什麼我討厭格萊德:(

+0

工作,謝謝。 – gsingh2011

+0

不客氣 – luciomrx