Sample Code 2: How to change the size of GtkWindow?
Written by kksou   
Tuesday, 12 September 2006
Problem

You want to change the size of GtkWindow as shown below:

How to change the size of GtkWindow?


Solution
Use GtkWidget::set_size_request (int width, int height)
$window->set_size_request(400, 100);

Sample Code
1   
2   
3   
4   
5   
6   
7   
<?php
$window = new GtkWindow();
$window->set_size_request(400, 100);

$window->connect_simple('destroy', array('Gtk','main_quit'));
$label = new GtkLabel("hello world!");
$window->add($label);
  • 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
  • $window->set_size_request(400,100) sets the window size to width=400, height=100.

  • If you set only the width, e.g. $window->set_size_request(400,-1) you will get:

  • Note that GTK will adjust the height for you automically to fit the height of the label.

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


Notes

set_size_request works on most other widgets, including hbox, vbox, buttons, labels, etc.

For example, you can use $label->set_size_request(48,36) to set the size of a label.


User reviews   Average user ratings:    4.5   (from 3 users)
  1. Nathan Matteson
    March 06, 2008 8:44am

  2. Adam Blake
    March 10, 2008 9:46am

  3. Sebastian Gebhard
    April 02, 2008 1:16am

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