2.4 Right align the button |
|
Written by kksou
|
|
Tuesday, 18 March 2008 |
Objective
In the previous example, you have displayed the button in its default size as shown below:

What if we want the button to be right aligned?
Overview
- Create a GtkButton.
- Create a GtkHBox.
- First pack an expandable box into the hbox. Remember to set
expand=true.
- Then pack the button inside the hbox, set
expand=false.
- Finally pack the hbox inside the vbox, also set
expand=false.
Sample Output

Sample Code
1 2 3 4 5 6 7 8 9 10 11
| <?php $window = new GtkWindow(); $window->connect_simple('destroy',array('Gtk','main_quit')); $window->set_size_request(200, 100); $vbox = new GtkVBox(); $window->add($vbox);
$button = new GtkButton('button label'); $hbox = new GtkHBox(); $hbox->pack_start(new GtkLabel(), true); // note 1
$hbox->pack_start($button, false); // note 2
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation
- Here our expandable box is an empty GtkLabel with
expand=true. Note that you may also use an empty GtkHBox or GtkVBox. The effect is the same.
expand=false will ensure that the button does not expand horizontally in the hbox.
expand=false will ensure that the button does not expand vertically in the vbox.
The net result is that the empty GtkLabel, because of its expandable spring, will "push" the button on the way to the right of the window, as the following diagram illustrates.

|