How to make svg icons crisp again in Qt 5.6 on high DPI screens

会有一股神秘感。 提交于 2020-07-18 07:42:26

问题


Upgrading from Qt 5.4 to Qt 5.6 made all my .svg icons blurry/pixelated. I noticed this happens only on high density screens like on my MacBookPro Retina Display. I read the documentation of High DPI support in Qt 5.6 and I have set the QT_AUTO_SCREEN_SCALE_FACTOR=1 environment variable, but it didn't have much effect. Anybody has this issue? I have also found this bug report which probably relates to my question.

EDIT 1:

A simple example would be:

Image {
  source: my_icon.svg
  sourceSize.width: 50
  sourceSize.height: 50
  anchor.centerIn: parent
}

回答1:


This is an ugly hack, but it did the trick:

Item {
    property alias image: mySvgImage

    implicitWidth: mySvgImage.paintedWidth
    implicitHeight: mySvgImage.implicitHeight / Screen.devicePixelRatio

    Image {
        id: mySvgImage

        sourceSize.width: width * Screen.devicePixelRatio
        sourceSize.height: height * Screen.devicePixelRatio
    }
}



回答2:


I'm not sure how to apply this in QML, but you need to set the attribute AA_UseHighDpiPixmaps with QWidgets. Might well be the same with QML. E.g:

app.setAttribute(Qt.AA_UseHighDpiPixmaps)


来源:https://stackoverflow.com/questions/37976644/how-to-make-svg-icons-crisp-again-in-qt-5-6-on-high-dpi-screens

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!