2.5 Center the button horizontally
Written by kksou   
Wednesday, 19 March 2008

Objective

You have right aligned the button in the previous example as shown below:

2.4.gif

What if you want the button to be centered horizontally?

Overview

Instead of stuffing one spring box, we stuff two – one on each side as illustrated below:

2.51.gif


Sample Output

2.5.gif

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 GtkHBox(), true); // note 1
$hbox->pack_start($button, false);
  • 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

  1. This is the spring box on the left. Just for illustration sake, we use a hbox here to show you that the effect is the same as using an empty GtkLabel.
  2. This is the spring box on the right. Just for illustration sake, we use a vbox here to show you that the effect is the same as using an empty GtkLabel.


User reviews

There are no user reviews yet.

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Copyright © 2006-2008. kksou.com. All Rights Reserved