Yes it is really not clear what you want. But if you want to draw on a rectangle, you might want to try using the Canvas element instead. Try this:
import QtQuick 2.1
Canvas {
property int prevX
property int prevY
property int lineWidth: 2
property color drawColor: "black"
MouseArea {
id:mousearea
anchors.fill: parent
onPressed: {prevX = mouseX ; prevY = mouseY}
onPositionChanged: requestPaint();
}
onPaint: {
var ctx = getContext('2d');
ctx.beginPath();
ctx.strokeStyle = drawColor
ctx.lineWidth = lineWidth
ctx.moveTo(prevX, prevY);
ctx.lineTo(mousearea.mouseX, mousearea.mouseY);
ctx.stroke();
ctx.closePath();
prevX = mousearea.mouseX;
prevY = mousearea.mouseY;
}
}
↧