我有这个密码:
#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
行,它将重新开始工作。为什么会这样?我遗漏了什么吗?
最佳答案
因此,通过阅读问题的答案,我了解到gtk_window_set_default_size
不起作用,所以我用这个代替了gtk_window_set_default_size
:
GdkGeometry windowProperties;
windowProperties.min_width = 230;
windowProperties.min_height = 150;
gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &windowProperties, GDK_HINT_MIN_SIZE);