【问题标题】:Wrong screen size value屏幕尺寸值错误
【发布时间】: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 是两者之间的乘数。

标签: qt qml size screen


【解决方案1】:

我是这样制作的:DPI Awareness.
这个answer 帮助了我。

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);
    ...
}

我将“windows”更改为“android”。
现在它可以正常工作了。
虽然功能不是为 android 设计的。
在我删除附加代码字符串后,它仍然可以正常工作。
应用程序在初始状态下运行良好。 切换到 Qt 中。

【讨论】:

    猜你喜欢
    • 2015-12-03
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多