Search code examples
qtqmlsizescreen

Wrong screen size value


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


Solution

  • Comment this

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);