gtk_window_set_default_size不起作用

时间:2014-08-17 20:39:15

标签: c gtk gtk3

我有这段代码:

#define false FALSE
#define true TRUE
#include <gtk/gtk.h>

int main( int argc, char *argv[]){
    GtkWidget *window;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    gtk_window_set_title(GTK_WINDOW(window), "window");

    gtk_window_set_default_size(GTK_WINDOW(window), 230, 150);
    gtk_window_set_resizable(GTK_WINDOW(window), false);

    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), 0);

    gtk_widget_show(window);

    gtk_main();

    return 0;
}

当我使用下面的代码编译代码并运行它时,窗口最终为1x1px

gcc src/main.c -o test -Wall -O2 `pkg-config --libs --cflags gtk+-3.0`

如果我删除gtk_window_set_resizable行,它会重新开始工作。

为什么会这样?我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

因此,通过阅读this问题的答案,我了解到gtk_window_set_default_size不起作用,因此我将gtk_window_set_default_size替换为{<1}}:

GdkGeometry windowProperties;
windowProperties.min_width = 230;
windowProperties.min_height = 150;
gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &windowProperties, GDK_HINT_MIN_SIZE);