PDA

View Full Version : change color on dragging curve



bchinfosieeuw
9th August 2016, 00:41
I can put a bezier curve on a MouseArea on mouseclick. I can even drag and drop it. But how can I change the color of the curve while dragging it? My code:



Item {
Path {
id: mycurve
startX: -132; startY: -12
PathCurve { x: -138; y: -14 }
PathCurve { x: -140; y: -20 }
PathCurve { x: -146; y: -22 }
}
Rectangle {
id: rect
width: 2
height: 2
color: "black"
border.color: "black"


MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: {mycurve.color = "red";}//what should I do here?
onReleased: {mycurve.color = "black";}//what should I do here?
onPositionChanged: {
if (mouse.buttons & Qt.LeftButton) {
mycurve.x -= (x - mouse.x); mycurve.y = (y - mouse.y); ;
}

}
}
PathView {
id: pathView1;
x: 158
width: 708
model: 300;
path: mycurve
delegate: Rectangle {
id: dot;
width: 1; height: 1;
color: "black"
ColorAnimation on color { to: "red"; duration: 0 }//my own attempt
}
}
}
}

anda_skoa
9th August 2016, 08:32
mycurve is currently only a standard Path, it doesn't have a color property.

Add one and use it in the delegate or add the property to any other object that both the delegate and the mouse are have access to.

Cheers,
_

bchinfosieeuw
9th August 2016, 13:02
Solved. Thank you.