Force the use of a horizontal or vertical screen in QT applications

Source: Internet
Author: User
From Forum Nokia Wiki


Summary: This article describes how to force the use of a horizontal or vertical screen in the QT for Symbian program even when the phone's horizontal status is changed.

For Symbian phones with a horizontal sensor, when the user switches the phone from landscape mode (Landscape) to vertical screen mode (Portrait), the screen orientation of the phone is automatically adjusted to meet the user's normal usage needs. Changes in the aspect ratio of the screen require the layout of the adjustment window to be applied to ensure a better user experience.

However, in some special occasions (such as games), the developer may want to even if the phone's horizontal status has changed, need to continue to maintain the screen orientation, prompting the user to use the current application only in the horizontal or vertical screen direction, which needs to be set, so that the phone screen is forced to be in a horizontal screen or vertical screen state.

The current version of Qt (Qt-4.6.2) does not provide an API to directly control the Symbian Phone screen mode, which needs to be done by using Symbian's API. The Set API function is: Caknappui::setorientationl (); The usage display code in QT is as follows:

#ifdef Q_os_symbian
void Mywidget::setportraitmode ()
{
    Caknappui *aknappui = dynamic_cast<caknappui * > (Ceikonenv::static ()->appui ());
    if (AKNAPPUI)
        aknappui->setorientationl (caknappui::eappuiorientationportrait);
}
void Mywidget::setlandscapemode ()
{
    Caknappui *aknappui = Dynamic_cast<caknappui *> (ceikonenv::static ()->appui ());
    if (AKNAPPUI)
        aknappui->setorientationl (Caknappui::eappuiorientationlandscape);
}
#endif

To use the Symbian function in the code above, we need to add several Symbian related header files to the source code.

#ifdef Q_os_symbian
#include <eikenv.h>
#include <coemain.h>
#include <aknappui.h >
#endif

and need to include the following in Qt's. Pro project file to ensure that the app compiles and links

Symbian {
    LIBS + =-lconnmon-lcone-lavkon
}

Note: This feature cannot be simulated on the emulator, but it works correctly on Symbian phones.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.