我想用單個LinearGradient
作爲背景,跨越幾個同級Rectangle
s。在每個Rectangle
中,您可以看到漸變的不同部分。 我使用OpacityMask
來「填充」Rectangle
s的梯度。 LinearGradient
width
是各個總和Rectangle
width
。在幾個矩形上跨度漸變
如果我使用單一的Rectangle
,它的工作原理。從兩開始,無論我嘗試什麼,它都表現不正確(我在下面的代碼中留下想象)。到目前爲止,我得到的最好結果是在每個Rectangle
中重複使用LinearGradient
的相同部分。 我想我可以使用一個LinearGradient
每Rectangle
,改變GradientStop
值,但它看起來很複雜,我想有一個簡單的優雅的解決方案。
Rectangle
{
id: page1
// anchors.fill: parent
// id: masqCont
anchors.centerIn: parent
border.color: "blue"
width: childrenRect.width
height: childrenRect.height
visible: false
Rectangle
{
id: masq1
y:0
border.color: "red"
border.width: 10
width: 100
height: 100
radius: 40
Text {text: "Un"}
visible: true
}
Rectangle
{
x:width
id: masq2
border.color: "red"
border.width: 10
width: 100
height: 100
radius: 40
Text {text: "deux"}
Text {text: "deux"}
visible: true
}
}
LinearGradient {
id:grad
width: 200 //masqCont.childrenRect.width
height: 100//masqCont.childrenRect.height
//anchors.fill: masqCont
start: Qt.point(0, 0)
end: Qt.point(200,100)//masqCont.width, masqCont.height)
gradient: Gradient {
GradientStop { position: 0.0; color: "white" }
GradientStop { position: 1.0; color: "black" }
}
visible: false
}
OpacityMask {
id: om21
anchors.fill: page1;
source: grad
maskSource: page1;
}
// OpacityMask {
// id: om21
// anchors.fill: masq1;
// source: grad
// maskSource: masq1;
// }
// OpacityMask {
// id: om22
// anchors.fill: masq2;
// source: grad
// maskSource: masq2;
// }
// }
// }
謝謝,這就是我一直在尋找的。我期望這種代碼可以很快寫出來。 –