Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt android screen orientation
Forum Updated to NodeBB v4.3 + New Features

Qt android screen orientation

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 326 Views 1 Watching
  • 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.
  • Z Offline
    Z Offline
    ZINE
    wrote on 17 Aug 2019, 23:06 last edited by
    #1

    Hi,

    Is there a way to set the screen orientation in Qt 5.12.3 programmatically, and without changing the AndroidManifest.xml file ?

    K 1 Reply Last reply 22 Aug 2019, 13:02
    0
    • Z ZINE
      17 Aug 2019, 23:06

      Hi,

      Is there a way to set the screen orientation in Qt 5.12.3 programmatically, and without changing the AndroidManifest.xml file ?

      K Offline
      K Offline
      KroMignon
      wrote on 22 Aug 2019, 13:02 last edited by KroMignon
      #2

      @zine Hi, it is simple to change screen orientation from Qt:

          enum Orientation
          {
              Unlocked = 4,           // SCREEN_ORIENTATION_SENSOR    (Android)
              LandscapeLocked = 0,    // SCREEN_ORIENTATION_LANDSCAPE (Android)
              PortraitLocked = 1,     // SCREEN_ORIENTATION_PORTRAIT  (Android)
          };
      
      void setOrientation(Orientation orientation)
      {
          const QAndroidJniObject Activity = QtAndroid::androidActivity();
          QAndroidJniEnvironment JniEnv;
      
          Activity.callMethod<void>("setRequestedOrientation", "(I)V", orientation);
          if(JniEnv->ExceptionCheck())
          {
              qDebug() << "setOrientation:: failed to set orientation!!!";
              JniEnv->ExceptionDescribe();
              JniEnv->ExceptionClear();
          }
      }
      
      

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      3

      1/2

      17 Aug 2019, 23:06

      • Login

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