GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Jul 26, 2014 3:07 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Getting problem in using GtkAlignment
PostPosted: Thu Jan 23, 2014 10:27 am 

Joined: Sat Dec 21, 2013 10:04 am
Posts: 4

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 am missing something.

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);

    return 0;

 Post subject: Re: Getting problem in using GtkAlignment
PostPosted: Fri Jan 24, 2014 2:54 am 
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
Don't use GtkAlignment in new code:
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.

Also Gtkbox is eventually going away. The manual suggests you use GtkGrid instead.

Migrating from other containers to GtkGrid:

I used gtk_widget_set_halign and gtk_widget_set_valign in the Signals I and II tutorials:

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group