Skip to content

How to control the orientation of an application in Qt

By default, S60 applications choose the current orientation automatically based on how the user is holding the device. This is convenient in general, but in some cases the developer needs more control regarding the orientation of the displayed content. In this post I will show you how to override this behavior and set the preferred orientation for your application: portrait, landscape or automatic at run time.

The first thing that we need is to include a couple of libraries: cone, eikcore and avkon. This can be done by editing the Symbian specific part of the .pro file:

symbian {
TARGET.UID3 = 0xe9507491
TARGET.EPOCHEAPSIZE = 0x020000 0x800000
# We need these libs to change the orientation
LIBS += -lcone \
-leikcore \

Now we have to include the specific headers wherever we want to change the orientation of the device:

//These are the headers needed for changing the orientation
#include <eikenv.h>
#include <eikappui.h>
#include <aknenv.h>
#include <aknappui.h>

Now we can just call to this function and the orientation will be changed to portrait, no matter how the user holds the device:

CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
    if (appUi) {

You can do the same for Landscape or Automatic mode. Just change EAppUiOrientationPortrait to EAppUiOrientationLandscape or EAppUiOrientationAutomatic accordingly. Automatic is the default mode, that is, it will change the orientation depending on how the user holds the device.
Make sure that you do not remove the Symbian OS checks (#ifdef Q_OS_SYMBIAN) because these libraries will only be available for the Symbian device, and not for the simulator for example.
Feel free to download the source code of an example that I made for controlling the orientation in Qt.

Posted in Programming, Qt.

2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Vadim says

    How to get current orientation of Synbian device?

Some HTML is OK

or, reply to this post via trackback.