×
Namespaces

Variants
Actions
Revision as of 23:44, 8 June 2009 by tepaa (Talk | contribs)

Archived:Listening for screen orientation changes in Qt

From Nokia Developer Wiki
Jump to: navigation, search
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(), QMainWindow::resizeEvent()
Created: (08 Jun 2009)
Last edited: tepaa (08 Jun 2009)

Contents

Overview

This code snippets shows how to listen screen / layout orientation changes. When using Qt layout managers you generally does not need to worry about layout changes, layout managers does it.

You have to handle screen orientation and size changes on custom UI applications that do not use layout managers by implementing virtual QWidget::resizeEvent().


Note: In order to use this code, you need to have Qt for S60 installed on your platform.


Preconditions


Source

Solution 1: Asking 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: Asking 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 handled.

83 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.

×