【发布时间】:2020-03-26 20:45:38
【问题描述】:
我创建了测试 QML 应用程序来显示屏幕大小。
在小米 Redmi 6 上测试。设备屏幕分辨率为 720 x 1440 像素。
我有 360 x 696。有什么想法吗?
Windows 7 64 位,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);
}
}
}
控制台输出:
D libTest2_armeabi-v7a.so: qml: 696 360
【问题讨论】:
-
Screen.devicePixelRatio 返回什么?
-
Screen.devicePixelRatio = 2, Screen.pixelDensity = 5.8032258064516125
-
Android Studio 中的下一个 Java 代码,{} ` 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)); `产生的结果:`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:高度 = 1344.0 `
-
那么预计,360x696是“逻辑分辨率”,用于QtQuick中的坐标、字体缩放等。720x1440是实际像素的物理分辨率。 devicePixelRatio 2 是两者之间的乘数。