Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Problem with Canvas loading pictures

$
0
0
Hello! I have written the following code: import QtQuick 2.0   Rectangle {     width: 360     height: 360       Canvas {         id: canvas         property string path: ""           anchors.fill: parent         renderStrategy: Canvas.Immediate           MouseArea {             anchors.fill: parent             onClicked: {                 canvas.path == "/home/user/1.png" ? canvas.path = "/home/user/2.png" : canvas.path = "/home/user/1.png"                 console.log(canvas.path)                 canvas.loadImage(canvas.path)             }         }           onImageLoaded: {             var context = getContext("2d")             context.clearRect(0, 0, canvas.width, canvas.height)             context.drawImage(canvas.path,  0, 0);             canvas.requestPaint();         }     } } Clicking for the first time shows 1.png. Clicking for the second time shows 2.png. When I click for the third time 1.png is not shown. How can I achieve that? Best regards, Oliver.

Viewing all articles
Browse latest Browse all 4972

Trending Articles