Dynamically change rectangle gradient
-
wrote on 18 Nov 2013, 12:27 last edited by
I am trying to dynamically change a Rectangle gradient, but I'm not sure the syntax. This does not work:
@ Rectangle{
id:tt
width: height
height: parent.height*1.5
color: "black"
anchors.centerIn: parentgradient: Gradient { GradientStop { position: 0.0; color: "lightsteelblue" } GradientStop {position: 1.0; color: "blue" } } MouseArea{ onEntered: { tt.gradient=Gradient{ GradientStop { position: 0.0; color: "red" } GradientStop {position: 1.0; color: "yellow" } } } }@
This won't even compile, the onEntered contents are not proper syntax, but I'm not sure how to manipulate the gradient in there.
Any ideas?
-
wrote on 18 Nov 2013, 12:59 last edited by
i managed to do this not by adjusting the gradient directly, but by making the colors property's of the rectangle and binding the gradient to those properties, and then adjusting those properties from the mouse area.
-
wrote on 26 Nov 2013, 05:46 last edited by
You can define a bool property supposed "overArea" in Rectangle and in the gradient use "color: overArea ? "lightsteelblue" : "red". besides that, set the property values in the MouseArea onEntered and onExited events, don't forget to set anchors.fill and hoverEnable property of MouseArea
-
wrote on 8 Jan 2015, 19:09 last edited by
I got the same trouble, how to dynamical adjust gradient.stops(insert/remove/clear)? I want to create a GradientColorPicker controls. tks lots
-
wrote on 8 Jan 2015, 19:09 last edited by
I got the same trouble, how to dynamical adjust gradient.stops(insert/remove/clear)? I want to create a GradientColorPicker controls. tks lots