Solved Geometry wrong on iOS device
-
Hi, I've got existing Qt/C++ project for embedded devices and desktop. I'm trying to port it to iOS which works but I'm having issues with getting the main QQuickView fullscreen or scale properly. It always show a little window in the middle of the screen - no matter what I try it's always the same. Available geometry seems to always be 319x479 no matter what device is used. This doesn't to be linked to our code or qml because if I just put QQuickView in the main with just a simple rectangle it looks the same (same window in the middle of the screen with different content).
We are not using qmake nor QtCreator. We are using XCode project generated by cmake. So I'm wondering if there is some special magic qmake does when targeting iOS I'm not aware of?
Thanks
-
Can you provide a code fragment please? How exactly you show this QQuickView on the screen? Did you try to call showFullScreen() for it instead of just show() for example?
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQuickView *view = new QQuickView; view->setSource(...); view->showFullScreen(); return app.exec(); }
-
This post is deleted! -
Yes, so if I just create simple qml - using your example:
#import <QQuickView> #include <QtPlugin> Q_IMPORT_PLUGIN(QtQuick2Plugin) #endif int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQuickView *view = new QQuickView; view->setSource(QUrl::fromLocalFile("/tmp/simple.qml")); view->showFullScreen(); return app.exec(); }
and the QML:
import QtQuick 2.0 Rectangle { id: page width: 300; height: 200 color: "yellow" Text { id: helloText text: "Hello world!" y: 30 anchors.horizontalCenter: page.horizontalCenter font.pointSize: 24; font.bold: true } }
This is the result:
-
@_eph Try to call viewer->setResizeMode(QQuickView::SizeRootObjectToView) before calling showFullScreen().
-
@KoneTaH said in Geometry wrong on iOS device:
viewer->setResizeMode(QQuickView::SizeRootObjectToView)
The yellow now fills the whole white box and the text is centered but it's still contained to the same window as before.
-
@_eph This one works for me:
main.cpp:
#include <QGuiApplication> #include <QQuickView> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQuickView *view = new QQuickView(QUrl(QStringLiteral("qrc:/main.qml"))); view->showFullScreen(); return app.exec(); }
main.qml:
import QtQuick 2.0 Rectangle { anchors.fill: parent color: "red" Rectangle { width: 100 height: 100 color: "yellow" anchors.centerIn: parent } }
Qt 5.12.1.
-
Are you using qmake/qtcreator?
Looks the same for me:
-
@_eph Yes, it's a qmake project ("Qt Quick Application - Empty" template with changes in main.cpp and main.qml), I build it using both Qt Creator and XCode, and see no difference - it work as expected.
-
Yeah, there must be something qmake does which makes the difference...
-
@_eph Here is an example of Qt cmake QML project for iOS with QQuickView:
https://github.com/forexample/qt-ios-examples/tree/master/qml-custom-property-types
In main.cpp it imports some plugin called "QIOSIntegrationPlugin". May be you should import it too?
-
@KoneTaH Tried but no difference :(
-
@_eph Please note that main() in iOS case is called qtmn(). It's not the real main() and it will be called from this plugin after some initial setup (as I think).
-
@KoneTaH Yeah, that doesn't work (it's looking for undefined _main).
Btw. I needed to force load the ios plugin and use _qt_main_wrapper for the app to work at all.
-
@_eph
I would suggest using a properWindow
as the root item instead of a rectangle or something like that
https://doc.qt.io/qt-5/qml-qtquick-window-window.htmland do not set a width or height for the root item. it should scale automatically - except for "safe zones"
-
Hi @_eph , you need to have proper splash screen, otherwise your app comes like this, so every Iphone has a different size for the splash screen, so you need to prepare a splash screen with respect to the device you are deploying on and after that you need to include it in a file called info.plist, same is the case with app icons also.
For more info you can have a look into this: -[https://doc.qt.io/qt-5/ios-platform-notes.html]
For info on the sizes you can have a look at this:- [https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/launch-screen/]
I guess once you have proper splash screen,the app will cover the complete Iphone screen.
-
@J.Hilk Makes no difference the QML is always contained in the same window/rectangle you see on the first screenshot.
-
@Shrinidhi-Upadhyaya Hm, I don't really see connection between the launch image (splascreen) and the actual app since you don't need that kind of thing when you use Qt Creator and qmake but I will try it anyway. Thanks
-
@_eph Do you have some minimal CMake project with this issue somewhere in public? Usually I don't use CMake, but I can take a look (as well as others, I think).
-
@Shrinidhi-Upadhyaya OMG, you are the man! It really helped, I can't believe it lol. Adding a dummy launch storyboard made it go fullscreen... Unbelievable