Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

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.beginPath();
     context.lineWidth = 2;
     context.moveTo(currentSegment.firstPtX(), currentSegment.firstPtY());
     context.strokeStyle = "white"
     //context.setLineDash(5) does not work
     context.lineTo(endX, endY);
     context.fill();
     context.stroke();
    

    }@

    PS: Using Qt 5.4


  • Moderators

    Hi,

    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