这是我的qtquick qml代码。
function show_me(element) {
console.log(element.gradient)
}
Rectangle {
gradient: Gradient {
GradientStop {
position: 0
color: "#30cfd0"
}
GradientStop {
position: 1
color: "#330867"
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
show_me(parent)
}
}
}
输出是
qml: QQuickGradient(0x559f18a4dd40)
输出给我一个QtQuickGradient对象。
我想知道如何在javascript中定义一个QtQuickGradient对象?
我想这样的东西。
var gradient = //QtQuickGradient (i don't know)
element.gradient = gradient
请帮我定义一下
你可以创建 Gradient
俗物 Component
比如说,项目。
Component {
id: myGradient
Gradient {
GradientStop { position: 0.0; color: "red" }
GradientStop { position: 0.5; color: "yellow" }
GradientStop { position: 1.0; color: "green" }
}
}
Rectangle {
id: rect
width: 100
height: 100
anchors.centerIn: parent
color: "orange"
Text {
anchors.centerIn: parent
text: "click me"
}
TapHandler {
onTapped: {
var gradient = myGradient.createObject(rect);
rect.gradient = gradient;
}
}
}