Qt Reference Documentation

Maemo 5 Rotation Example

Files:

The Maemo 5 Rotation example shows how to use widget flags to set an application to either landscape, portrait or automatic rotation.

Screenshot of the Rotation example

         setAttribute(Qt::WA_Maemo5PortraitOrientation, true);

Qt applications are always shown in landscape mode by default. In order to set the application to portrait (vertical) orientation the Qt::WA_Maemo5PortraitOrientation attribute must be set on a top-level widget.

         setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);

Qt::WA_Maemo5LandscapeOrientation sets the top-level widget into landscape (horizontal) orientation.

         setAttribute(Qt::WA_Maemo5AutoOrientation, true);

In order to make the application auto-rotate depending on the current device orientation, Qt::WA_Maemo5AutoOrientation must be set on a top-level widget.

Note: The device's rotation sensor will be enabled when auto-orientation is switched on, which will drain extra battery power.

Note: Auto-rotation will only work when the sliding hardware keyboard is in closed state, otherwise auto-rotation will always set the application into landscape mode.

         connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged()));

Qt will handle rotation behind the scenes and re-layout all widgets accordingly. In order to explicitly react on screen rotation, the QDesktopWidget::resized() signal can be used. This signal is emitted every time the device's screen rotates.

     void orientationChanged()
     {
         QRect screenGeometry = QApplication::desktop()->screenGeometry();
         if (screenGeometry.width() > screenGeometry.height())
             label->setText("<p align=\"center\">In Landscape Mode</p>");
         else
             label->setText("<p align=\"center\">In Portrait Mode</p>");
     }

If the current screen's width is larger than its height, the application is in landscape mode, otherwise in portrait mode.

Note that Maemo 5 currently only supports landscape and portrait. Reversed landscape or reversed portrait applications are currently not possible.

X

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.

[0]; s.parentNode.insertBefore(ga, s); })();