I am trying to create very simple application in QT QML using QtQuick 2.7. I added on the canvas one rectangle, and after pushing the button I want to add another rectangle. Problem is, that the rectangle which should appear after button click is not created (I cannot see it on canvas), but console.log() output Button 1 cliceked I see. What I am doing wrong? Is there any need to refresh the canvas or something? My code is:
Page1Form {
property alias canvas: canvas
button1.onClicked: {
console.log("Button 1 clicked.");
var ct = canvas.getContext("2d");
ct.fillStyle = Qt.rgba(0, 0, 1, 1);
ct.fillRect(50, 50, 10, 10);//this doesnt work
}
Canvas {
id: canvas
x: 16
y: 39
width: 342
height: 517
onPaint: {
var ctx = getContext("2d");
ctx.fillStyle = Qt.rgba(1, 1, 1, 1);
ctx.fillRect(10, 10, 10, 10);
}
}
}