I'm stumbling through Gtk+ tutorials and the reference, trying to understand how to get a decent layout done. The docs say you should use GtkGrid
instead of the deprecated Box/HBox/VBox, but I’m having trouble getting the GtkGrid
to expand to the full window size. Using gtk_widget_set_hexpand
has no effect on the GtkGrid
at all.
This answer suggests "looking at the expand
property" but I can't find information about what this properties actually are and how you set them (I just assumed there always is a getter/setter pair for each property, but in this case there is no gtk_widget_set_expand
function).
What am I missing?
Update:
Setting the expand property still won't work - the buttons "stick" in the top left corner of the window. Here's the code:
static void initializeGui() {
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Blabla");
gtk_window_set_default_size(GTK_WINDOW(window), 800, 500);
gtk_window_set_hide_titlebar_when_maximized(GTK_WINDOW(window), TRUE);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_signal_connect(window, "delete-event", G_CALLBACK(onWindowDelete), NULL);
g_signal_connect(window, "destroy", G_CALLBACK(onWindowDestroy), NULL);
GtkWidget *mainbox = gtk_grid_new();
g_object_set(G_OBJECT(mainbox), "expand", TRUE, NULL);
GtkWidget *button = gtk_button_new_with_label("Short button");
g_signal_connect(button, "clicked", G_CALLBACK(onButtonClick), NULL);
gtk_grid_attach(GTK_GRID(mainbox), button, 0, 0, 1, 1);
button = gtk_button_new_with_label("Very very long button");
gtk_grid_attach(GTK_GRID(mainbox), button, 1, 0, 1, 1);
button = gtk_button_new_with_label("Tiny btn");
gtk_widget_set_halign(button, GTK_ALIGN_END);
gtk_grid_attach(GTK_GRID(mainbox), button, 1, 1, 1, 1);
gtk_container_add(GTK_CONTAINER(window), mainbox);
gtk_widget_show_all(window);
}