2

I created test QML application to show screen size.

It tested on Xiaomi Redmi 6. Device screen resolution is 720 x 1440 pixels.

I have got 360 x 696. Any ideas?

Windows 7 64 bit, Qt 5.14.1, jdk1.8.0_241.

main.qml:

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    visible: true
    width: 720
    height: 1440
    title: qsTr("Hello World")

    Column {
        anchors.centerIn: parent

        Text {
            text: "Screen.width: " + Screen.width
            color: "lightsteelblue"
        }

        Text {
            text: "Screen.height: " + Screen.height
            color: "lightsteelblue"
        }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            // ScreenSize == QGuiApplication::primaryScreen()->size()
            console.log( ScreenSize.height, ScreenSize.width);
        }
    }

}

console output:

D libTest2_armeabi-v7a.so: qml: 696 360

Screenshot

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Denis
  • 21
  • 2
  • What does Screen.devicePixelRatio return? – Frank Osterfeld Mar 26 '20 at 06:59
  • Screen.devicePixelRatio = 2, Screen.pixelDensity = 5.8032258064516125 – Denis Mar 26 '20 at 07:27
  • Next Java code in Android Studio,{} ` DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); Log.d("MY_DEBUG", "WIDTH = " + Float.toString(metrics.widthPixels)); Log.d("MY_DEBUG", "HEIGHT = " + Float.toString(metrics.heightPixels)); ` produced result: ` 2020-03-26 13:48:12.097 9773-9773/? D/MY_DEBUG: WIDTH = 720.0 2020-03-26 13:48:12.097 9773-9773/? D/MY_DEBUG: HEIGHT = 1344.0 ` – Denis Mar 26 '20 at 08:51
  • It’s expected then, 360x696 is the “logical resolution”, used for coordinates in QtQuick, font scaling, etc. 720x1440 is the physical resolution of actual pixels. The devicePixelRatio 2 is the multiplier between the two. – Frank Osterfeld Mar 26 '20 at 12:51

2 Answers2

0

I made like this: DPI Awareness.
This answer helped me.

int main(int argc, char *argv[])
{
    argc = 3;
    argv[0] = (char*)"Appname";
    argv[1] = (char*)"--platform";
    argv[2] = (char*)"android:dpiawareness=0";

    QGuiApplication app(argc, argv);
    ...
}

I changed "windows" to "android".
Now it works correctly.
Although feature don't design for android.
After I delete append code string and it works correctly anyway.
Application works good in the initial state. Something switched into Qt.

Denis
  • 21
  • 2
0

Comment this

QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
S At
  • 422
  • 5
  • 15