Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved How to draw dashed line in Canvas

    QML and Qt Quick
    2
    3
    1317
    Loading More Posts
    • 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.
    • M
      Mark81 last edited by

      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?

      J.Hilk 1 Reply Last reply Reply Quote 0
      • J.Hilk
        J.Hilk Moderators @Mark81 last edited by

        @Mark81

        ctx.setLineDash = [ 1, 4 ]

        AFAIK setlineDash is a function ->

        ctx.setLineDash( [ 1, 4 ] )
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply Reply Quote 1
        • M
          Mark81 last edited by

          Ups, you're right. I didn't notice that because I received no warnings/error at compile-time nor at run-time!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post