Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

android screen width always 360?



  • hi all,

    i am new to qml on android. i have created a sample app (using qt creator's "Qt Quick Application - Empty") , put the code below in main.cpp, and then run it on android devices,

    QScreen* primaryscreen = QGuiApplication::primaryScreen();
    QRect rect = primaryscreen->geometry();
    qreal width = qMin(rect.width(), rect.height());
    qreal height = qMax(rect.width(), rect.height());
    qDebug() << "w: " << (width) << ", h: " << (height);
    

    oneplus one (android 7.1.2), w: 360, h: 640
    redmi 5 (android 7.1.2), w: 360, h: 660
    Huawei P10 plus (android 7.1.2), w: 360, h: 660

    it seems width is always 360 and height is around 600 something, although the native resolution of all 3 devices are very different. i googling around and can't find doc explaining this 360 figure.

    is it a expected behavior?

    thx in advance!

    py

    PS: qt 5.11.2 open source, running on ubuntu 16.04 LTS


  • Moderators

    hi @pyhk said in android screen width always 360?:

    try it with availableGeometry



  • thanks for pointing out availableGeometry()

    but the result is still the same. it seems QGuiApplication "masks" the underlying, real screen resolution, and QGuiApplication::primaryScreen() is always 360x600 something. at least it is what looks liked on android device.

    (i have tried a windows 10 tablet, with 3840×2160 display. the availableGeometry() returns 1920x1080. QGuiApplication does have some magic in itself)

    py



  • oh, my mistake.

    i haven't paid attention to the very 1st line of code in the main.cpp, which is:

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    

    after changing it to AA_DisableHighDpiScaling, the geometry(), availableGeometry(), etc work as expected.

    thanks

    py


Log in to reply