Archived:Handle change in screen orientation in Qt
m (Hamishwillee - Use warning note template)
m (Hamishwillee - Fix categories)
|Line 1:||Line 1:|
Revision as of 02:39, 30 June 2011
S60 5th Edition
The issue is in the example code's ResizeEvent::GetScreenCoordinates() method. The GetScreenCoordinates uses QDesktopWidget::availableGeometry and QDesktopWidget::screenGeometry methods. In all cases these methods do not reflect current screen geometry values during QWidget::resizeEvent call as the respective values are only changed after the resizeEvent has occured. This means that e.g. during the startup of the application these may return wrong values as the values are not yet set properly.
If the whole screen geometry information is needed from QDesktopWidget it's advised to connect to QApplication::desktop()'s workAreaResized(int) signal and call QApplication::desktop()->availableGeometry() in the connected slot function. This works in Qt 4.7.3 in Symbian but not (due to bug) in Qt 4.6.
See following bug report for more details. The QTBUG-14058's fix introduces documentation for QDesktopWidget on this issue.
In many cases application should however get simply the geometry of the main window using simplyQMainWindow::width() and ::height() methods during QMainWindow's resizeEvent.
This code example shows how to get notification when the screen mode changes using QWidget::resizeEvent(). This method gets called when the screen mode changes, so you have to implement that virtual method in your class.
This snippet can be self-signed.
- Download and install the Qt SDK
//resizeEvent() method get called when user change screen mode.
void ResizeEvent::resizeEvent (QResizeEvent* event)
QSize widgetSize = event->size();
//Resize your custom control according to new size.
The code snippet is expected to notify change in screen mode.
Download Code Example
- File:QtResizeEvent.zip shows new screen size when user change screen mode. This example is tested on Nokia 5800 XpressMusic.