Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    QML and Qt Quick
    qml qtquick2 orientation
    1
    2
    1117
    Loading More Posts
    • 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
      Praveen_2017 last edited by Praveen_2017

      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 Reply Quote 0
      • P
        Praveen_2017 last edited by Praveen_2017

        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 Reply Quote 0
        • P
          Praveen_2017 last edited by Praveen_2017

          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 Reply Quote 0
          • First post
            Last post