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



  • 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.



  • 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"



  • 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?



  • 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.



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

    It works, great.



  • just add [solved] to the topic and no problem



  • 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? :)



  • 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? :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.