canvas.step dought
Unsolved
QML and Qt Quick
-
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(); } } } }