[英]High dpi scaling in Qt application make icons smoothed out
I have enabled high dpi support in my Qt application using QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
我已经使用QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
在Qt应用程序中启用了高dpi支持QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
but now my images don't look crisp, instead they look "smoothed" out. 但是现在我的图像看起来不清晰,而是看起来“平滑”了。 For example below there is a picture of some button that are meant to be using high dpi images. 例如,下面有一些打算使用高dpi图像的按钮的图片。 When I disable the high dpi support and manually scale the ui, using the same images the icons are crisp and clear. 当我禁用高dpi支持并手动缩放ui时,使用相同的图像,图标清晰明了。
I have tried to set Qt::AA_UseHighDpiPixmaps
with no success. 我尝试设置Qt::AA_UseHighDpiPixmaps
没有成功。 Here is a sample code: 这是一个示例代码:
import QtQuick 2.11
import QtQuick.Window 2.11
import QtQuick.Controls 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
ToolButton{
anchors.centerIn: parent
icon.source: "qrc:/ic_star_white_48dp.png"
}
}
The icon I am using is from Google material design icons and it is made for a high dpi screen device (resolution is 192x192). 我使用的图标来自Google物料设计图标,它是为高dpi屏幕设备(分辨率为192x192)制成的。 Enabling high dpi the icon in the toolbutton appears smoothed out. 启用高dpi时,工具按钮中的图标将变平滑。 If I disable the high dpi support and set the height and width of the icon ( icon.height
and icon.width
) to 640/160 * 48
( 640
is the dpi of my device) the icon is crisp and clear. 如果禁用高dpi支持,并将图标的高度和宽度( icon.height
和icon.width
)设置为640/160 * 48
( 640
是设备的dpi),则图标清晰明了。 However, if I enable high dpi and set the height and width to 48
, the icon is not crisp. 但是,如果启用高dpi并将高度和宽度设置为48
,则图标不清晰。
I guess Qt's icon property scales images to increase performance (Eg the ToolButton is 48 x 48 the source image will be scaled to 48 x 48), but doesn't compensate for HighDpiScaling. 我猜想Qt的icon属性可以缩放图像以提高性能(例如ToolButton为48 x 48,源图像将被缩放为48 x 48),但不能补偿HighDpiScaling。
For example your ToolButton is scaled from 48 x 48 logical to 192 x 192 physical pixels by HighDpiScaling, but it is still using the downscaled 48 x 48 image. 例如,通过HighDpiScaling,您的ToolButton从48 x 48逻辑像素缩放到192 x 192物理像素,但是它仍在使用缩小的48 x 48图像。
I tend to use: 我倾向于使用:
ToolButton{
anchors.centerIn: parent
Image {
anchors.centerIn: parent
anchors.margins: 5
//You can play around with those to balance quality and performance
//mipmap: true
//sourceSize.height: height * 2
//sourceSize.width: width * 2
fillMode: Image.PreserveAspectFit
source: "qrc:/image.png"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.