2016-07-06 55 views
2

我有一個居中的矩形,背後有一個投影以及其中的一些文字。調整窗口大小時文字變得模糊

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。

+0

這可能是與你的窗口管理器,不改變窗口大小的問題。您在KWin中設置了哪些效果?改變效果是否也會影響您的問題? (Shift-Alt-F12啓用/禁用合成,KWin設置等) – user23573

+0

@BogdanWilli我做了更改渲染後端和禁用等離子體合成器的組合,但結果相同。 – DanielJG

回答

1

解決方案1:僅對背景矩形使用DropShadow並在其上繪製文本。

解決方案2:使用積分寬度和高度爲centerRect。圖形效果首先將centerRect渲染到紋理中。如果源寬度或高度不是整數,紋理大小將不對應於原始項目大小。繪製紋理時,紋理座標不會精確地撞擊像素位置,需要進行一些插值。

+0

結束使用解決方案1。 – DanielJG

1

對我來說,最簡單的是將文本移出centerRect,所以它不會是它的子對象,所以不會受到DropShadow副作用的影響。 如:

移動之外的文本,修改其調理象下面這樣:

Text{ 

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

}