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
Qt 6.11 is out! See what's new in the release blog

Qt android screen orientation

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 396 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 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 ?

    KroMignonK 1 Reply Last reply
    0
    • Z ZINE

      Hi,

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

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on 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

      • Login

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