【问题标题】:High dpi scaling in Qt application make icons smoothed outQt 应用程序中的高 dpi 缩放使图标变得平滑
【发布时间】:2018-08-07 01:00:15
【问题描述】:

我使用QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 在我的Qt 应用程序中启用了高dpi 支持,但现在我的图像看起来不清晰,反而看起来“平滑”了。例如,下面有一些按钮的图片,这些按钮旨在使用高 dpi 图像。当我禁用高 dpi 支持并手动缩放 ui 时,使用相同的图像,图标清晰明了。

我尝试设置Qt::AA_UseHighDpiPixmaps,但没有成功。 这是一个示例代码:

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"
    }
}

我使用的图标来自谷歌材料设计图标,它是为高 dpi 屏幕设备制作的(分辨率为 192x192)。启用高 dpi 工具按钮中的图标会显得平滑。如果我禁用高 dpi 支持并将图标的高度和宽度(icon.heighticon.width)设置为640/160 * 48640 是我设备的 dpi),则图标清晰明了。但是,如果我启用高 dpi 并将高度和宽度设置为48,则图标不清晰。

【问题讨论】:

  • 赢了?林?苹果电脑?移动的?我没有答案,也许对我也很重要。
  • 抱歉忘了说,我在安卓上测试

标签: android qt qml highdpi


【解决方案1】:

我猜 Qt 的图标属性会缩放图像以提高性能(例如 ToolButton 是 48 x 48,源图像将被缩放到 48 x 48),但不能补偿 HighDpiScaling。

例如,您的 ToolButton 通过 HighDpiScaling 从 48 x 48 逻辑像素缩放到 192 x 192 物理像素,但它仍然使用缩小后的 48 x 48 图像。

我倾向于使用:

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"
    }
}

【讨论】:

    猜你喜欢
    • 2014-08-13
    • 2013-12-26
    • 1970-01-01
    • 2018-11-30
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多