Qt 6.9.1 Android screen scale factor issues.
-
I am trying to understand what is and what is not possible in terms of screen scaling and presentation with applications witten using qmake, designer and C++.
I have just setup a development environment using qtcreator (17), jdk-24.0.1, qt-6.9.1 gradle (8.14), sdk(19) and ndk (27.2.12479018) and have ported one of my projects to this setup as a test application.My application has migrated quite well, my biggest problem currently is the the way the app presents itself on different targets.
I am currently testing on an X86_64 simulator phone, Samsung A06 phone, Samsung Tab9 tablet and an HTC 2022 pro phone.
They all look and behave slightly different the Tab9 being the best with the test app nicely centered (in landscape) on the screen with very little wasted space above and the below.
The A06 is the worst with the app falling off the bottom left of the screen (again in landscape). Things tend to fall apart on all devices if the device is in portrait mode.As a starting point I have used the following after a Google trawl, I am hoping there is a better way to take control of my apps look and feel.
int main(int argc, char *argv[])
{
QApplication *app=new QApplication(argc, argv);
QScreen *sc=app->primaryScreen();
qreal ratio=1.0/(sc->devicePixelRatio());
qputenv("QT_SCALE_FACTOR", QString::number(ratio).toLocal8Bit());
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR","0");
delete app;
app = new QApplication(argc, argv);
...
}Any suggestions welcome.
-
Thank you for your comment. During my journey to set up an android build enviromment I tried various combinations of build tool versions the set I am currently using produces working apk files for my selected set of deployment targets.
-
@SMF-Qt I used Qt5 + old versions of sdk and jdk and did not have your issue on Tablet and Phone with Android 12/13/14.
-
I am currently trying to find a c++ programmatic method for locking my application into landscape mode.
I have seen on the web various methods (including copying and hacking build xml files) to acheive this but so far nothing constructive that support my Qt6 setup.
I have found "setRequestedOrientation" references in various java files under the sdk and I know there was a Qt5 method for accessing it but nothing currently in Qt6.Any suggestions welcome.
-
I am currently trying to find a c++ programmatic method for locking my application into landscape mode.
I have seen on the web various methods (including copying and hacking build xml files) to acheive this but so far nothing constructive that support my Qt6 setup.
I have found "setRequestedOrientation" references in various java files under the sdk and I know there was a Qt5 method for accessing it but nothing currently in Qt6.Any suggestions welcome.
@SMF-Qt said in Qt 6.9.1 Android screen scale factor issues.:
I am currently trying to find a c++ programmatic method for locking my application into landscape mode.
you can try
bool ApplicationUI::setScreenOrientationLandscape() { QJniObject activity = QNativeInterface::QAndroidApplication::context(); if(activity.isValid()) { activity.callMethod<void>("setRequestedOrientation", "(I)V", 0); return true; } return false; }
-
@SMF-Qt said in Qt 6.9.1 Android screen scale factor issues.:
I am currently trying to find a c++ programmatic method for locking my application into landscape mode.
you can try
bool ApplicationUI::setScreenOrientationLandscape() { QJniObject activity = QNativeInterface::QAndroidApplication::context(); if(activity.isValid()) { activity.callMethod<void>("setRequestedOrientation", "(I)V", 0); return true; } return false; }
Thank you that worked.
-
Thank you that worked.
@SMF-Qt cool :)