| ID | CS001437 | Creation date | June 18, 2009 |
| Platform | S60 3rd Edition, FP1, FP2 S60 5th Edition | Tested on devices | Nokia 5800 XpressMusic |
| Category | Qt for Symbian | Subcategory | UI |
| Keywords (APIs, classes, methods, functions): QWidget::resizeEvent(), QMainWindow::resizeEvent() |
This code snippet demonstrates how to listen for screen or layout orientation changes. When using Qt layout managers, they handle the layout changes and you generally do not need to worry about them.
On custom UI applications that do not use layout managers, you have to handle screen orientation and size changes by implementing a virtual QWidget::resizeEvent().
The event handler resizeEvent() of the base class QWidget is called whenever the user changes the screen mode. This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter. QMainWindow is a subclass of QWidget and it contains resizeEvent() as well, so you can also get the resize event from QMainWindow if you implement it in your application.
This snippet can be self-signed.
Solution 1: Requesting the new size from QResizeEvent
void QMyWidget::resizeEvent (QResizeEvent* event)
{
QSize widgetSize = event->size();
// TODO: You have new size of the screen
// do your new layout
// Call base class impl
QWidget::resizeEvent(event);
}
Solution 2: Requesting the new size from QMainWindow's central widget
void QMyMainWindow::resizeEvent (QResizeEvent* event)
{
QSize widgetSize = centralWidget()->size();
// TODO: You have new size of the screen
// do your new layout
// Call base class impl
QMainWindow::resizeEvent(event);
}
CS001308 - Implementing a layout manager in Qt
Dynamic Layout handling with QWidget
Layout orientation and size change are handled. You will get a notification when the user changes the screen mode.