2.4 Right align the button
Written by kksou
Tuesday, 18 March 2008
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?
- Create a GtkButton.
- Create a GtkHBox.
- First pack an expandable box into the hbox. Remember to set
- Then pack the button inside the hbox, set
- Finally pack the hbox inside the vbox, also set
| 1 |
$window = new GtkWindow();
$vbox = new GtkVBox();
$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.
- 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.