Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Drawing a dashed/dotted line on a canvas element
Forum Updated to NodeBB v4.3 + New Features

Drawing a dashed/dotted line on a canvas element

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheMeerd
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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.

      157

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved