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 Oct 25, 2014 11:33 pm

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 
Offline

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

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.

Code:
    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

Thanks



Code:
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;
}


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

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
Don't use GtkAlignment in new code:
Quote:
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.
https://developer.gnome.org/gtk3/stable/GtkAlignment.html#GtkAlignment.description

Also Gtkbox is eventually going away. The manual suggests you use GtkGrid instead.
https://developer.gnome.org/gtk3/stable/GtkHBox.html#gtk-hbox-new

Migrating from other containers to GtkGrid:
https://developer.gnome.org/gtk3/stable/gtk-migrating-GtkGrid.html

I used gtk_widget_set_halign and gtk_widget_set_valign in the Signals I and II tutorials:
http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=196066=SIGNALS+I#p196066
http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=196067=SIGNALS+I#p196067


Top
 Profile  
 
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 1 guest


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group