Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.8.1
-
None
-
Tested that the behavior is the same with 6.5.3 and 6.8.1 (on macOS).
Description
If the size of Canvas changes while the Canvas is not visible, we do not get a call to onPaint(). If the Canvas is later made visible, the content looks stretched.
Example to see the effect.
import QtQuick import QtQuick.Controls.Basic Window { width: 640 height: 480 visible: true title: qsTr("Canvas repainting") Rectangle { anchors.fill: mycanvas color: "grey" } Canvas { id: mycanvas anchors.centerIn: parent width: 100 height: 100 onPaint: { print("onPaint", "visible:", visible, "height:", height) var ctx = getContext("2d"); // Use random color to make it easier to see when onPaint() was called ctx.fillStyle = Qt.rgba(Math.random(),Math.random(),Math.random(), 1); ctx.fillRect(10, 10, width - 20, height - 20); ctx.strokeStyle = "pink" ctx.lineWidth = 4 ctx.beginPath() ctx.moveTo(10, 10) ctx.lineTo(width - 20, 50) ctx.closePath() ctx.stroke() } } Row { anchors.bottom: parent.bottom spacing: 10 Button { text: "Reset size" onClicked: { // Reset the situation to test again. mycanvas.height = 100; } } Button { text: "Size change while not visible" onClicked: { // This sequence does not result in mycanvas.onPaint(). // As we still change the Canvas height, the result look stretched. mycanvas.visible = false; mycanvas.height = 200; mycanvas.visible = true; } } } }