16.8. Size of Widget
You can use the following methods to find out the size of a widget in several different ways.
16.8.1. Widget's Geometry
The geometry method returns the geometry string for the widget in the form of widthxheight+x+y.
$geom = $widget->geometry();
The geometry string was discussed in detail in Chapter 13. Geometry values are specified in pixels.
16.8.2. Requested Height
The height of the widget is returned by the reqheight method:
$height = $widget->reqheight();
The widget itself determines the appropriate height.
16.8.3. Requested Width
The width of the widget can be determined by using the reqwidth method:
$width = $widget->reqwidth();
16.8.4. Actual Width
To get the width of the widget as it currently is drawn, use the width method:
$cur_width = $widget->width();
When the widget is first created, width will return a 1 until the application has finished drawing everything. After that, it will return the actual width of the widget.
16.8.5. Actual Height
To get the current height, use the height method:
$h = $widget->height();
Just like the width method, height returns a 1 when the widget is first created. You can use the update or the afterIdle method to force everything else to happen and then call heightor widthto get the finished values.