2

I've been searching for a solution to this but I could only find a way to force the whole app to stay in either landscape or portrait, via the android manifest. In my app the user is able to customize his UI and one important aspect of that is the screen orientation. I'd like to create a button where the user could change the orientation and lock it that way.

Thank you for your time.

Solidus
  • 698
  • 1
  • 9
  • 23
  • I guess you came across [this](http://stackoverflow.com/questions/20774498/qml-screen-orientation-lock) ? – Thomas Ayoub Jun 15 '15 at 14:57
  • I saw that but the solution is with android manifest, which as far as I can tell (through my google search, which might be wrong) is applicable to the whole app and not when a user presses a button. – Solidus Jun 15 '15 at 15:11
  • 1
    Make a native call and use the approach in [this answer](http://stackoverflow.com/a/9837247/2538363)? – BaCaRoZzo Jun 15 '15 at 16:40
  • Hm, that looks like a possible solution but as far as I can tell the "setRequestedOrientation" is a method from the Activity class, from the Android API? Correct? How can I access that via the qt's c++/qml? – Solidus Jun 16 '15 at 13:50

1 Answers1

0

I don't think it is possible through QML but you may bind your qml button to change orientation by setting orientation of QQmlApplicationViewer object. You may find some information here. In my experience I remember I forced orientation only in C++.

So, you may need a class to export to QML which will toggle orientation (by setting value to the QQmlApplicationViewer and bind it with your button/checkbox in your qml interface.

VP.
  • 15,509
  • 17
  • 91
  • 161
  • A solution with C++ is perfectly fine for me but I don't seem to find the QQmlApplicationViewer. I believe that was changed with QT5? I am using QT5.4, – Solidus Jun 15 '15 at 15:09
  • I will check tonight how I did this before. I pretty sure if `QQmlApplicationViewer` does not exists in Qt5 then it is just renamed/it's interfaces delegated to some another class. – VP. Jun 15 '15 at 15:19