[英]How to define QML gradient object in javascript
This is my qtquick qml code这是我的 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)
}
}
}
The output is output 是
qml: QQuickGradient(0x559f18a4dd40)
the output gives me a QtQuickGradient object output 给了我一个 QtQuickGradient object
I wonder how do I define a QtQuickGradient object in javascript?
我想知道如何在 javascript 中定义 QtQuickGradient object?
I want to something like:我想要类似的东西:
var gradient = //QtQuickGradient (i don't know)
element.gradient = gradient
Please help me to define it请帮我定义它
You can create the Gradient
object using common Component
item, for example:您可以使用通用
Component
项创建Gradient
object,例如:
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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.