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. [SOLVED] How to fix screen orientation to landscape in Quick 2 ?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to fix screen orientation to landscape in Quick 2 ?

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 9.0k 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.
  • J Offline
    J Offline
    jackmack
    wrote on last edited by
    #1

    Hi all,

    I have written a simple QML game and it runs on my Nexus 7 (API 14). The game is designed to play in landscape mode and I want to fix it. That means if I rotate my Nexus the screen should also stay in landscape. The user has only the chance to play in landscape.

    I'm using Qt SDK 5.2 with Creator 3.0 on Windows.

    It sounds strange but I cannot find somewhere information how I can fix the orientation. A lot of threads about reading the "Screen", "Sensors" I found. But no solution.

    Most threads are based on older versions Qt 4.7.x and Creator < 3.0. In earlier versions of Creator you could enter the screen orientation with the AppWizard. Then a "qmlapplication class" was generated with a method called setOrientation() which simple sets QDeclarativeView::setAttribute(Qt::WA_LockLandscapeOrientation, true).

    But this is only available in Quick 1. I use Quick 2!!!!!

    Have anybody a simple solution? I don't think for that simple function I have to read sensor and so on. Come on!

    Thanks a lot.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kolegs
      wrote on last edited by
      #2

      I am not sure how to change it in QML but you can do it in AndroidManifest
      "Click":http://stackoverflow.com/questions/582185/android-disable-landscape-mode just change "portrait" to "sensorLandscape" or "landscape"

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jackmack
        wrote on last edited by
        #3

        Sounds good. But the problem is that in Creator 3.0 there is no android directory existing like older Creator versions :-(

        The only AndroidManifest.xml files (one in /android-build and one in /android-build/bin) are created always new with every deployment.

        Therefore I can add 'android:screenOrientation="portrait" ' to AndroidManifest.xml... but it's overwritten.

        Other solutions?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kolegs
          wrote on last edited by
          #4

          Just go to the projects, running, click on details and create androidmanifes.xml, choose a directory. After that add it to your project if it didnt happen automaticly and edit it. 4th line should look like this:
          @<activity android:screenOrientation="unspecified" android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="@string/app_name">@ just change "unspecified" to "sensorLandscape" and save it. It won't be overwritten every time you deploy.

          I do it this way and it works perfectly.

          BTW "sensorLandscape" is much better I belive coz the app will never be upside down.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jackmack
            wrote on last edited by
            #5

            Thanks for the quit response. I found out the same ;-)

            It works, great.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kolegs
              wrote on last edited by
              #6

              just add [solved] to the topic and no problem

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mikyago
                wrote on last edited by
                #7

                Mybe i did something wrong, but after i created a template (i'm using qt 3.3) i am not able to build anymore, any idea? :)

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mikyago
                  wrote on last edited by
                  #8

                  Mybe i did something wrong, but after i created a template (i'm using qt 3.3) i am not able to build anymore, any idea? :)

                  1 Reply Last reply
                  0

                  • Login

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