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 issue

Drawing issue

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 485 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
    Tikani
    wrote on last edited by
    #1

    Hi! I use Canvas in my project to free draw anything with mouse, but while drawing all traces come out like on the picture below.

    Drawing issue example

    Here below is my code responsible for drawing:

        Canvas {
            id:canvas
            anchors.top: parent.top
            width: 640
            height: 410
    
            onPaint: {
                var ctx = getContext('2d')
    
                if(clearCanvas) {
                    ctx.fillStyle = "white"
                    ctx.fillRect(0,0,width,height)
                    clearCanvas=false
                }
                else {
                    ctx.lineWidth = 30
                    ctx.strokeStyle = 'blue'
                    ctx.beginPath()
                    ctx.moveTo(xpos,ypos)
                    xpos = area.mouseX
                    ypos = area.mouseY
                    ctx.lineTo(xpos, ypos)
                    ctx.stroke()
                }
            }
    
            MouseArea {
                id:area
                anchors.fill: parent
                acceptedButtons: Qt.LeftButton | Qt.RightButton
    
                onPressed: {
                    if(mouse.buttons & Qt.LeftButton) {
                        hold=true
                        xpos = mouseX
                        ypos = mouseY
                    }
                }
    
                onPositionChanged: {
                    if(hold & (mouse.buttons & Qt.LeftButton)) {
                        canvas.requestPaint()
                    }
                }
    
                onReleased: {
                    hold = false
                }
    
                onClicked: {
                    infoArea.visible = false
                }
            } 
    

    Finally I want to have a solid line without gaps. Count on your help!

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

      @Tikani Set lineCap to round

      ctx.lineCap = 'round';
      

      157

      1 Reply Last reply
      2

      • Login

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