PHP-GTK2 Newsletter
PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou
Sample Code 107: How to set the button to the exact size you want - Part 3 - group of buttons? |
|
Written by kksou
|
|
Monday, 04 December 2006 |
|
Problem You would like to center a group of buttons, all of size 80x32, as shown below:

Solution
- Create the buttons with GtkButton.
- Pack the buttons in a GtkHBox.
- Create an alignment container with GtkAlignment, and set the desired x/y aligntment and x/y scale.
- Stuff the hbox inside the aligment container.
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <?php $window = new GtkWindow(); $window->set_size_request(400, 150); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Set the size of button to exactly 80 x 32\nGroup of buttons - using GtkAlignment"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 40); $vbox->pack_start($title, 0, 0);
$hbox = new GtkHBox(); // note 1
for ($i=0; $i<3; ++$i) { $button = new GtkButton('button '.($i+1)); $button->set_size_request(80, 32); $button->connect('clicked', 'on_click'); $hbox->pack_start($button); $hbox->pack_start(new GtkLabel('')); // add a small gap
}
$alignment = new GtkAlignment(0.5, 0, 0, 0); $alignment->add($hbox); // 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
- Create the hbox to hold the buttons.
- Create a gtkalignment container. Here we set the x-alignment to be 0.5 to center the button.
- Stuff the hbox in the alignment container, and then pack the alignment container in turn in the containing vbox.
Related Links
User reviews There are no user reviews yet. Note: You have to be a registered member to leave a comment. Free registration here. |
|