我想用单个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;
// }
// }
// }
谢谢,这就是我一直在寻找的。我期望这种代码可以很快写出来。 –