Drawing a dashed/dotted line on a canvas element

  • Hello Everyone,

    I would like to draw simple dashed line on a canvas. Here is my sample code below. I had a look at
    properties/methods (i.e. setLineDash) for drawing the line in a "dotted" way but none of them worked for me. Am I missing something?

    @ onPaint: {
    var context = getContext("2d");

     context.lineWidth = 2;
     context.moveTo(currentSegment.firstPtX(), currentSegment.firstPtY());
     context.strokeStyle = "white"
     //context.setLineDash(5) does not work
     context.lineTo(endX, endY);


    PS: Using Qt 5.4

  • Moderators


    AFAIK not all HTML5 Canvas features have been ported in Qt's Canvas. According to "Context2d":http://doc.qt.io/qt-5/qml-qtquick-context2d.html doc there's no such method available. The only way I think for now is to use lineTo and moveTo functions to imitate it.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.