我LinearGradient用作矩形的背景,但矩形的左右邊界有點白且模糊。我怎樣才能避免這種情況?
我試圖在 Rectangle 上設定以下屬性,但它沒有用。
clip: true
smooth: true
antialiasing: true

這是我的代碼:
import QtQuick 2.15
import QtQuick.Window 2.15
import QtGraphicalEffects 1.15
Window {
width: 640
height: 480
visible: true
Rectangle {
anchors.fill: parent
color: "#4f4444"
}
Rectangle {
id: root
anchors.centerIn: parent
width: 355
height: 90
radius: 50
LinearGradient {
anchors.fill: parent
source: ShaderEffectSource {
sourceItem: root
recursive: true
}
start: Qt.point(0, 0)
end: Qt.point(parent.width, 0)
gradient: Gradient {
GradientStop { position: 0.0; color: "#2a3254" }
GradientStop { position: 1.0; color: "#0e1c57" }
}
}
Text {
anchors.centerIn: parent
text: "Click me!"
color: "white"
}
}
}
uj5u.com熱心網友回復:
root問題在于它正在平滑形狀的邊緣以與包含漸變 ( )的矩形混合。如果您更改該 Rectangle 的顏色以匹配其后面繪制的內容,您將不會再看到這些邊緣。
Rectangle {
id: bground
anchors.fill: parent
color: "#4f4444"
}
Rectangle {
id: root
color: bground.color // Match the background's color
LinearGradient { ... }
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/414854.html
標籤:
