我有一个居中的矩形,其后面有一个阴影,其中有一些文本。
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。
最佳答案
解决方案 1:仅对背景矩形使用 DropShadow
并在其上绘制文本。
解决方案 2:对 centerRect
使用整数宽度和高度。图形效果首先将 centerRect
渲染为纹理。如果源宽度或高度不是整数,则纹理尺寸将不对应于原始项目尺寸。绘制纹理时,纹理坐标不会准确命中像素位置,需要进行一些插值。
关于qt - 调整窗口大小时文本变得模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38217157/