How to lock Screen orientation QML (Android/iOS)?
-
-
Hi and welcome to devnet,
That configuration is OS specific so no, you'll have to do the configuration for both separately.
-
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(); } } }
}
@ -
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.
-
[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 -
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.
-
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
-
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.