How to draw dashed line in Canvas
Solved
QML and Qt Quick
-
This code draws a solid line:
Canvas { id: canvas onPaint: { var ctx = canvas.getContext('2d') ctx.strokeStyle = "red" ctx.lineWidth = 4 ctx.lineCap = "round" ctx.lineJoin = "round" ctx.setLineDash = [ 1, 4 ] ctx.beginPath() ctx.moveTo(2, canvas.height / 2) ctx.lineTo(canvas.width - 2, canvas.height / 2) ctx.stroke() } }
what I further have to set after
setLineDash
? -
This code draws a solid line:
Canvas { id: canvas onPaint: { var ctx = canvas.getContext('2d') ctx.strokeStyle = "red" ctx.lineWidth = 4 ctx.lineCap = "round" ctx.lineJoin = "round" ctx.setLineDash = [ 1, 4 ] ctx.beginPath() ctx.moveTo(2, canvas.height / 2) ctx.lineTo(canvas.width - 2, canvas.height / 2) ctx.stroke() } }
what I further have to set after
setLineDash
?