Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to lock screen Orientation(Windows) in QML 2 ?
QtWS25 Last Chance

How to lock screen Orientation(Windows) in QML 2 ?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlqtquick2orientation
2 Posts 1 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Praveen_2017
    wrote on 21 Sept 2017, 04:34 last edited by Praveen_2017
    #1

    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.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Praveen_2017
      wrote on 22 Sept 2017, 05:43 last edited by Praveen_2017
      #2

      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 .

      1 Reply Last reply
      0

      2/2

      22 Sept 2017, 05:43

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved