How to lock Screen orientation QML (Android/iOS)?
-
wrote on 11 Dec 2014, 19:20 last edited by
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? -
Hi and welcome to devnet,
That configuration is OS specific so no, you'll have to do the configuration for both separately.
-
wrote on 26 Jan 2015, 08:21 last edited by
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.0import "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(); } } }
}
@ -
wrote on 26 Jan 2015, 09:25 last edited by
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.
-
wrote on 26 Jan 2015, 10:10 last edited by
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.4And I am seeking the same solution
-
wrote on 26 Jan 2015, 10:43 last edited by
[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 -
wrote on 26 Jan 2015, 14:52 last edited by
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.
-
wrote on 26 Jan 2015, 15:57 last edited by
Seems like we now got both approaches; for Android and for iOS.
-
wrote on 26 Jan 2015, 16:08 last edited by
Am I correct?:
- 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) - 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.htmlTomorrow morning I will try this staff. Now I need cooling my brain :-) Result will be noticed.
- For Android I need to make this
-
wrote on 27 Jan 2015, 09:11 last edited by
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.