You Are Here:

Community: Wiki

This page was last modified on 3 September 2009, at 07:44.

CS001437 - Listening for screen orientation changes in Qt

From Forum Nokia Wiki


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()

Overview

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.

Preconditions


Source

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);
}


See also

CS001308 - Implementing a layout manager in Qt

Dynamic Layout handling with QWidget


Postconditions

Layout orientation and size change are handled. You will get a notification when the user changes the screen mode.

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia