调整大小时文本变得模糊 window

Text becomes blurry when resizing window

我有一个居中的矩形,后面有一个阴影,里面有一些文本。

import QtQuick 2.5
import QtQuick.Window 2.2
import QtGraphicalEffects 1.0

Window {

    visible: true
    width: 800; height: 640

    Rectangle{

        id: centerRect
        width: parent.width * 0.7; height: parent.height * 0.7

        anchors{
            horizontalCenter: parent.horizontalCenter
            verticalCenter: parent.verticalCenter
        }

        radius: 7
        border.color: "#C0C0C0"

        Text{

            text: "Hello World!"
            font.pixelSize: 0.07 * parent.height

            anchors{

                horizontalCenter: parent.horizontalCenter
                verticalCenter: parent.verticalCenter
            }
        }
    }

    DropShadow
    {
        anchors.fill: centerRect
        horizontalOffset: 1; verticalOffset: 1
        radius: 5
        samples: 11
        color: "#CDCDCD"
        source: centerRect
    }
}

当我调整 window 大小时,文本变得稍微模糊或无法聚焦。我认为这可能是我如何将字体像素大小缩放到矩形高度的问题,但问题与静态值相同。如果我删除阴影效果,当我调整 window.

大小时文本的可见性很好

如何在使用投影和调整 window 大小时保持良好的文本可见性?我在 OpenSUSE Leap 42.1 (Plasma 5.5.5) 上使用 Qt 5.5.1。

解决方案 1:仅对背景矩形使用 DropShadow,并在其上绘制文本。

解决方案 2:为 centerRect 使用整数宽度和高度。图形效果首先将 centerRect 渲染为纹理。如果源宽度或高度不是整数,则纹理大小将不对应于原始项目大小。绘制贴图时,贴图坐标不会准确命中像素位置,需要进行一些插值。

对我来说,最简单的就是将Text移出centerRect,这样就不会是它的child obj,不受DropShadow副作用的影响。 例如:

将文本移到外面并修改其条件,如下所示:

Text{

    text: "Hello World!"
    font.pixelSize: 0.07 * centerRect.height
    anchors.centerIn: centerRect

}