0
votes

I am new to GTK+ world and trying to learn it from Foundations of GTK+ Development.

Mean while I am getting some problem in using GtkAlignment widget, as in the code below.

Even if I change the value of either one of the below I am not getting the Ok and calcel button getting aligned to right.

GtkWidget* halign = gtk_alignment_new(0, 0, 0, 0);
GtkWidget* halign = gtk_alignment_new(0, 1, 0, 0);

I think I'm missing something, but not getting exactly

Note: I am using GTK+3 on windows 7

int main(int argc, char* argv[]) { gtk_init(&argc, &argv);

GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Gtk Alignment Sample");
gtk_container_set_border_width(GTK_CONTAINER(window), 5);
gtk_widget_set_size_request(window, 250, 400);
g_signal_connect(window, "delete_event", G_CALLBACK(gtk_main_quit), NULL);


GtkWidget* ok_button = gtk_button_new_from_stock(GTK_STOCK_OK);
GtkWidget* cancel_button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);

GtkWidget* hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start(GTK_BOX(hbox), ok_button,     FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), cancel_button, FALSE, FALSE, 0);

GtkWidget* halign = gtk_alignment_new(0, 0, 0, 0);
gtk_container_add(GTK_CONTAINER(halign), hbox);

GtkWidget* vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_start(GTK_BOX(vbox), halign, FALSE, FALSE, 0);

GtkWidget* valign = gtk_alignment_new(0, 1, 0, 0);
gtk_container_add(GTK_CONTAINER(valign), vbox);

gtk_container_add(GTK_CONTAINER(window), valign);
gtk_widget_show_all(window);

gtk_main();
return 0;

}

1

1 Answers

0
votes

Quote from the docs:

Note that the desired effect can in most cases be achieved by using the "halign", "valign" and "margin" properties on the child widget, so GtkAlignment should not be used in new code.

Try to just use

gtk_widget_set_alignment (button_ok, GTK_ALIGN_END);
gtk_widget_set_alignment (button_cancel, GTK_ALIGN_END);
//or
gtk_widget_set_alignment (hbox, GTK_ALIGN_END);

and remove all alignment widgets