PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou




1.5 Resize application window
Written by kksou   
Wednesday, 12 March 2008

Objective

We will resize the application window to 400 x 200 in this example.

Overview

Resize widgets (including GtkWindow) is easy with a call to the method GtkWidget::set_size_request().

Sample Output

1.5.gif

Sample Code

1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
12   
13   
14   
15   
16   
<?php
$window = new GtkWindow();
$window->connect_simple('destroy',array('Gtk','main_quit'));
$window->set_size_request(400, 200); // note 1
$vbox = new GtkVBox();
$window->add($vbox);

$label = new GtkLabel('Please click on the button: ');
//$label->set_size_request(100,50); // note 2
$vbox->pack_start($label);

$button = new GtkButton("click me!");
//$button->set_size_request(100,50); // note 2
$button->connect('clicked', 'on_click');
$vbox->pack_start($button);

  • 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. Resize the application window to 400x200.
  2. Note that if you specify only the width, e.g. $window->set_size_request(400,-1) you will get the following.

    1.51.gif

    If you specify only the height, e.g. $window->set_size_request(-1,200), you will get:

    1.52.gif

  3. Please see notes below.

Note

The method GtkWidget::set_size_request(). is supposed to work with all GtkWidgets, including GtkWindow, GtkLabel and GtkButtons. However, easy as it might seem, this is one area that frustrates a lot of people new to php-gtk.

  • Sometimes you "requested" the size for a widget, but the size remains unchanged. For example, try uncomment the two lines with "note 2" above. You will find that the label and the button remain as big!
  • Sometimes you changed the size of a container, and the widgets inside the containers automatically get resized too, messing up the layout and positioning. For example, the button in the previous example looks ok. But as soon as you resize the application window, the button becomes too huge.

Of course, there are always two sides to a coin. Please take a look at this example. A user can choose the calculator button size he or she likes by resizing the application window. Php-gtk2 automatically rearranges and resizes the widgets to fit the new window - without the need of you to do any programming!

So, how do we set the size of the label and button in php-gtk?

This leads us to the first fundamental building block of php-gtk: Size and Positioning.


 

Add comment


Security code
Refresh

< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Links - Classes - Social Business - BPM - Web - General
Copyright © 2006-2013. kksou.com. All Rights Reserved