Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. canvas.step dought
Qt 6.12 LTS is out! See what's new in the release blog

canvas.step dought

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 505 Views
  • 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.
  • S Offline
    S Offline
    saivineeth
    wrote on last edited by saivineeth
    #1

    Hi i have created a sine wave by using canvas.step
    why the screen is cleaning compeltly when u r canvas.step set to zero ??

    import QtQuick 2.9
    import QtQuick.Window 2.15
    
    Window {
        id: screen
        visible: true
        height: 1080
        width: 1920
        title: qsTr("SineWave")
    
        Rectangle {
            height: parent.height
            width: parent.width
    
            Timer {
                id: timer
                interval: 1
                running: true
                repeat: true
                onTriggered: {
                    if (canvas.step > 1921)
                        canvas.step =0
                        //timer.stop()
                    canvas.step++
                    canvas.requestPaint()
                }
            }
    
            Canvas {
                id: canvas
                property int step: 0
                anchors.fill: parent
                onPaint: {
                    var ctx1 = getContext("2d")
                    var cw = parent.width
                    var ch = parent.height
                    var cx = cw
                    var cy = ch/2
                    var w = width
                    var h = height
                    ctx1.lineWidth = 4
                    ctx1.clearRect(0, 0, cw, ch)
                    ctx1.beginPath()
                    ctx1.moveTo(0, cy)
                    for (var x = 0; x < canvas.step; x++) {
                       ctx1.lineTo(x, cy + (Math.sin(x / 305) * 400));
                        ctx1.fillStyle = Qt.rgba(0,255,0,255);
                        ctx1.fillRect(x+100, cy+100, 10, 1000);
                    }
    
                    ctx1.stroke();
                }
            }
    
    
        }
    }
    
    1 Reply Last reply
    0
    • U Offline
      U Offline
      UlrichS
      wrote on last edited by
      #2

      Hi, that's expected outcome. In your onPaint you clear the whole canvas area with:

      ctx1.clearRect(0, 0, cw, ch)
      

      on each paint event. If you remove that then the canvas is not cleared.

      Regards,
      Ulrich

      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
      • Unsolved