Qt: change color on dragging curve
Aug 8, 2016 at 10:10pm UTC
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
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
}
}
}
}
Last edited on Aug 8, 2016 at 10:11pm UTC
Aug 9, 2016 at 3:29am UTC
Maybe this can be adapted?
http://doc.qt.io/qt-4.8/qml-mousearea.html
Aug 9, 2016 at 11:51am UTC
SOLVED
Topic archived. No new replies allowed.