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. How to lock Screen orientation QML (Android/iOS)?
QtWS25 Last Chance

How to lock Screen orientation QML (Android/iOS)?

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 4 Posters 11.8k Views
  • 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.
  • B Offline
    B Offline
    bogong
    wrote on last edited by
    #1

    How do I need to do for locking screen orientation in QtQuick 2.3 My application is based on qt 5.4 and have to work on Androind and iOS. Does anybody know?
    The solution within manifest file is not fitted for iOS. Have this problem unique solution?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      That configuration is OS specific so no, you'll have to do the configuration for both separately.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bogong
        wrote on last edited by
        #3

        I am new-by in Qt. Could you help in this? What do I need to do?
        I've found solution:

        @
        function lockToLandscape() {
        screen.allowedOrientation = Screen.Landscape
        }
        @

        But I don't know where it must be placed in code.
        In main.qml I have this:
        @
        import QtQuick 2.3
        import QtQuick.Controls 1.2
        import QtQuick.Window 2.2
        import QtQuick.LocalStorage 2.0

        import "components/pages";

        Window {
        id: applicationWindow
        visible: true
        title: qsTr("application.com");

        function lockToPortrait(){
            screen.allowedOrientation = Screen.Portrait;
        }
        
        StackView {
            id: stackView;
            initialItem: PageSplashScreen{}
        }
        
        Rectangle {
            width: 10;
            height: 10;
            color: "green";
        
            MouseArea {
                anchors.fill: parent;
                onClicked: {
                    Qt.quit();
                }
            }
        }
        

        }
        @

        1 Reply Last reply
        0
        • O Offline
          O Offline
          onek24
          wrote on last edited by
          #4

          Hello and welcome to devnet,

          i want to refer to this Thread: "Stackoverflow - QML Screen Orientation Lock":http://stackoverflow.com/questions/20774498/qml-screen-orientation-lock

          As you can read, the proper way to do it for android is using the android manifest file. I wouldn't go ahead and do some nasty QML workaround.

          As i can read from "Symbian QML Screen":http://doc.qt.digia.com/qtquick-components-symbian-1.1/qml-screen.html your function seems to work with symbian, i don't know of any component where you can set the allowedOrientation so i assume this will actually only work on symbian.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bogong
            wrote on last edited by
            #5

            Thx a lot ... I know for android, there was an unique solution:
            @
            QDeclarativeView viewer;
            viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
            @
            But it's not working on Qt 5.4

            And I am seeking the same solution

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bogong
              wrote on last edited by
              #6

              [quote author="SGaist" date="1418328571"]Hi and welcome to devnet,

              That configuration is OS specific so no, you'll have to do the configuration for both separately.[/quote]

              What do I need to do in this case?
              Could you send me links or some information?
              I am not ant strong developer in Qt/QML

              1 Reply Last reply
              0
              • timdayT Offline
                timdayT Offline
                timday
                wrote on last edited by
                #7

                Don't know about Android but for iOS, this stuff is configured in the project's Info.plist

                See the mention in http://qt-project.org/wiki/Support_for_iOS of Info.plist which actually shows how to lock landscape orientations as an example of the sort of thing you can do with that file.

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  onek24
                  wrote on last edited by
                  #8

                  Seems like we now got both approaches; for Android and for iOS.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bogong
                    wrote on last edited by
                    #9

                    Am I correct?:

                    1. For Android I need to make this
                      @<activity android:configChanges="orientation|locale|fontScale|keyboard|
                      keyboardHidden|navigation" android:label="@string/app_name" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:screenOrientation="portrait">@
                      or something similar (In following this guidance "viewthread/29924":http://qt-project.org/forums/viewthread/29924)
                    2. For iOS I need to make this
                      @<key>UISupportedInterfaceOrientations</key>
                      <array><string>UIInterfaceOrientationLandscapeLeft</string><string>UIInterfaceOrientationLandscapeRight</string>
                      </array>@
                      In following this "http://qt-project.org/wiki/Support_for_iOS":http://qt-project.org/wiki/Support_for_iOS

                    [SOLVED] Where must be this files at time of compilation/run/deploy/etc?
                    "Solution for iOS 1.0":https://qt-project.org/faq/answer/how_do_i_add_a_custom_info.plist_to_my_mac_application_with_qmake
                    "Solution for iOS 1.1":http://doc.qt.io/qt-5/platform-notes-ios.html
                    "Solution for Android 1.0":https://qt-project.org/doc/qtcreator-2.8/creator-deploying-android.html

                    Tomorrow morning I will try this staff. Now I need cooling my brain :-) Result will be noticed.

                    1 Reply Last reply
                    1
                    • O Offline
                      O Offline
                      onek24
                      wrote on last edited by
                      #10

                      I can't tell for sure if the iOS part is right, but it seems all correct for me.
                      You can create your Android Manifest in your project configuration. It might be the same for iOS. The QtCreator should determine the files automatically(?), if not: you can still compile android project using ant.

                      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