问题描述
是否需要将sourceSize.width
和sourceSize.height
乘以Screen.devicePixelRatio,还是已经由Qt
自动管理?
即如果我将 width and height properties 设置为 1000,那么实际图像大小在普通显示器上为 1000x1000 物理像素,在 Retina 显示器上至少为 2000x2000 物理像素。
是否同样适用于 sourceSize.width
和 sourceSize.height
属性?
解决方法
根据代码的这一部分,我会说在这两种情况下 sourceSize 然后缩放(https://code.woboq.org/qt5/qtdeclarative/src/quick/items/qquickimagebase.cpp.html#263):https://code.woboq.org/qt5/qtdeclarative/src/quick/items/qquickimagebase.cpp.html#_ZN22QQuickImageBasePrivate22updateDevicePixelRatioEd(或者可能当你有一个@2x 文件时)。
这似乎是通过测试证实的:
Window {
width: 1920
height: 1080
visible: true
title: qsTr("Hello World")
Image {
id: testImage
anchors.fill: parent
source: "file:///..."
sourceSize.width: 1920
sourceSize.height: 1080
}
}
当像素比为 2 时,使用 file:// 方案的 png 图像以较低质量呈现。