【问题标题】:Text becomes blurry when resizing window调整窗口大小时文本变得模糊
【发布时间】:2016-07-06 05:57:19
【问题描述】:

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

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

当我调整窗口大小时,文本变得稍微模糊或失焦。我认为这可能是我如何将字体像素大小缩放到矩形高度的问题,但问题与静态值相同。如果我移除阴影效果,则在调整窗口大小时文本的可见性很好。

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

【问题讨论】:

  • 调整窗口大小的窗口管理器可能存在问题。您在 KWin 中设置了哪些效果?改变效果也会影响您的问题吗? (Shift-Alt-F12 启用/禁用合成、KWin 设置等)
  • @BogdanWilli 我做了更改渲染后端和禁用等离子合成器的组合,但结果是一样的。

标签: qt qml qtquick2


【解决方案1】:

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

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

【讨论】:

  • 最终使用解决方案 1。
【解决方案2】:

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

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

Text{

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

}

【讨论】:

    猜你喜欢
    • 2013-03-03
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    • 1970-01-01
    • 2023-02-23
    • 2018-04-26
    • 1970-01-01
    相关资源
    最近更新 更多