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.CAPABILITY += TARGET.EPOCSTACKSIZE = 0x14000< TARGET.EPOCHEAPSIZE = 0x020000 0x800000 # We need these libs to change the orientation LIBS += -lcone \ -leikcore \ -lavkon }
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 #ifdef Q_OS_SYMBIAN #include <eikenv.h> #include <eikappui.h> #include <aknenv.h> #include <aknappui.h> #endif
Now we can just call to this function and the orientation will be changed to portrait, no matter how the user holds the device:
#ifdef Q_OS_SYMBIAN CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi()); TRAPD(error, if (appUi) { appUi->SetOrientationL(CAknAppUi::EAppUiOrientationPortrait); } ) #endif
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.
Hi!
How to get current orientation of Synbian device?
tnx
This may help you:
http://www.developer.nokia.com/Community/Wiki/How_to_get_the_Current_Orientation