×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Handle change in screen orientation in Qt

From Nokia Developer Wiki
Jump to: navigation, search
Aleksi (Talk | contribs)
(Aleksi -)
Aleksi (Talk | contribs)
(Aleksi - - Note: This article is error prone, and needs code change in the example to work properly in Qt 4.7 in Symbian)
Line 22: Line 22:
 
==Note: This article is error prone, and needs code change in the example to work properly in Qt 4.7 in Symbian==
 
==Note: This article is error prone, and needs code change in the example to work properly in Qt 4.7 in Symbian==
  
'''PLEASE NOTE that the code in the arcticle doesn't work in Qt 4.7 on Symbian.''' The issue is in the example code's ResizeEvent::GetScreenCoordinates() method. The GetScreenCoordinates uses QDesktopWidget::availableGeometry and QDesktopWidget::screenGeometry methods. These methods do not in all cases reflect ''current'' values during QWidget::resizeEvent 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.
+
'''PLEASE NOTE that the code in the arcticle doesn't work properly in Qt 4.7 on Symbian.''' The issue is in the example code's ResizeEvent::GetScreenCoordinates() method. The GetScreenCoordinates uses QDesktopWidget::availableGeometry and QDesktopWidget::screenGeometry methods. These methods do not in all cases reflect ''current'' values during QWidget::resizeEvent 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.
  
 
If whole screen geometry 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.
 
If whole screen geometry 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.

Revision as of 10:18, 29 June 2011

{{{width}}}
16 Sep
2009
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
Article
Keywords: QWidget::resizeEvent()
Created: savaj (26 Jun 2009)
Last edited: Aleksi (29 Jun 2011)

Contents

Note: This article is error prone, and needs code change in the example to work properly in Qt 4.7 in Symbian

PLEASE NOTE that the code in the arcticle doesn't work properly in Qt 4.7 on Symbian. The issue is in the example code's ResizeEvent::GetScreenCoordinates() method. The GetScreenCoordinates uses QDesktopWidget::availableGeometry and QDesktopWidget::screenGeometry methods. These methods do not in all cases reflect current values during QWidget::resizeEvent 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.

If whole screen geometry 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.

Overview

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.

Preconditions

  • Download and install the Qt SDK

Source

//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.
QMainWindow::resizeEvent(event);
}

Postconditions

The code snippet is expected to notify change in screen mode.

Normal screen

ResizeEvent2.JPG

Screen after changing mode to portrait

ResizeEvent1.JPG

Related link

Download Code Example

  • File:QtResizeEvent.zip shows new screen size when user change screen mode. This example is tested on Nokia 5800 XpressMusic.


130 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×