How to lock screen Orientation(Windows) in QML 2 ?
Solved
QML and Qt Quick
-
Hello, I need to lock the orientation of my app but i am not finding any function to set the same. I am running the app in Microsoft Surface 3 and using QT 5.9.1. Please suggest.
-
I got to know that there is no such API to set Screen orientation in QT for windows and thus I used windows API for locking app Orientation, following is the code :
Just copy paste below code in
main.cpp
:#include <Windows.h> typedef enum ORIENTATION_PREFERENCE { ORIENTATION_PREFERENCE_NONE = 0x0, ORIENTATION_PREFERENCE_LANDSCAPE = 0x1, ORIENTATION_PREFERENCE_PORTRAIT = 0x2, ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = 0x4, ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = 0x8 } ORIENTATION_PREFERENCE; typedef BOOL (WINAPI *pSDARP)(ORIENTATION_PREFERENCE orientation); pSDARP pARP; pARP = (pSDARP) GetProcAddress( GetModuleHandle(TEXT("user32.dll")), "SetDisplayAutoRotationPreferences"); if( pARP ){ pARP( (ORIENTATION_PREFERENCE)(ORIENTATION_PREFERENCE_LANDSCAPE | ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED ) ); }
For more information please refer : Handling Windows Auto-rotate feature in your application Hope it helps others .