Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt 5.3.2 QML iOS : Manually set keyboard orientation
k.gaitanis last edited by
Here is my case : I'm writing a Qt application for iPhone which uses the OpenGL under QML paradigm (like the example provided by Qt). The OpenGL part uses the device's sensors (compass and accelerometer) to orientate the camera into a virtual world. QML is used to overlay the GUI on top of OpenGL.
Up to now, I have blocked the available device orientations to Portrait only and I have created QML Items that anchor and rotate themselves according to the orientation received from the QOrientationSensor. The OpenGL part does not need to know about orientation since the camera is oriented with the sensors.
All this is great! My GUI is placed exactly where I want it and I don't get the nasty iPhone automatic orientation animation whenever the user turns the phone.
Now i just included a TextInput QML item in my GUI which shows/hides the iPhone keyboard whenever it receives/loses focus. My TextInput item is rotated and anchored correctly just like all my other GUI elements. However the keyboard is always in Portrait mode which is normal since this is the only orientation available to my app. No need to say how ugly and unusable this is...
This is my question :
I want my app to only run in Portrait mode because I manually handle the device orientations. I do not need to display the iPhone status bar. How do I tell the keyboard in which orientation it should be displayed ?
By reading other threads and similar questions I came down to this solution :
Override UIViewController and
@return NO in -(BOOL)shouldAutorotate
return UIInterfaceOrientationMaskAll in -(NSUInteger)supportedInterfaceOrientations@
and then set the orientation of the statusbar
@([sharedApplication setStatusBarOrientation:newOrientation animated:NO])@
the keyboard should then be correctly oriented.
I have pointers to the UIView and the UIViewController using the private gui headers
@QPlatformNativeInterface* pnInterface = QGuiApplication::platformNativeInterface();
UIView view = static_cast<UIView>(pnInterface->nativeResourceForWindow("uiview", window()));
UIViewController *qtController = [[view window] rootViewController];
But I can't really understand how to override the above-mentioned methods without subclassing UIViewController (which I believe is not possible since it is handled by QML internally.)
This has been reported in "https://bugreports.qt-project.org/browse/QTBUG-38576":https://bugreports.qt-project.org/browse/QTBUG-38576 where they state "It's only possible to set by overriding UIViewController::supportedInterfaceOrientations". How can I accomplish that in QML?
Any ideas, comments, solutions ?
Thank you for your time.