Canvas/QPainter bug
-
Hi everyone,
I use Qt 5.11 and QtQuick 2.11, on windows OS.
I do have a bug on one of my application:
"
QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::setCompositionMode: Painter not active
QPainter::scale: Painter not active
QPainter::worldTransform: Painter not active
QPainter::worldTransform: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::brush: Painter not active
QPainter::setBrush: Painter not active
QPainter::font: Painter not active
QPainter::setFont: Painter not active
QPainter::opacity: Painter not active
QPainter::compositionMode: Painter not active
QPainter::setClipping: Painter not active, state will be reset by begin
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::compositionMode: Painter not active
QPainter::setCompositionMode: Painter not active
QPainter::setCompositionMode: Painter not active
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::pen: Painter not active
QPainter::setPen: Painter not active
QPainter::end: Painter not active, aborted
"And the area that is supposed to be painted is filled with black instead.
In order to isolate the problem I made a small application that can reproduce the bug:
"
import QtQuick 2.11
import QtQuick.Window 2.2
import QtQuick.Controls 2.4 as QtQuick2
import QtQuick.Controls 1.4 as QtQuick1Window {
visible: true
width: 1024
height: 768
title: qsTr("Hello World")
id:mainWindowQtQuick2.ScrollView { id: myScrollView anchors.fill: parent property real scaleFactor: 1 onScaleFactorChanged: myCanvas.requestPaint() contentItem: Canvas { id: myCanvas width: 200 * myScrollView.scaleFactor; height: 200 * myScrollView.scaleFactor onPaint: { var ctx = getContext("2d") ctx.save() ctx.lineWidth = 4 ctx.strokeStyle = "blue" ctx.fillStyle = "steelblue" ctx.beginPath() ctx.moveTo(0,0) ctx.lineTo(myCanvas.width,0) ctx.lineTo(myCanvas.width,myCanvas.height) ctx.lineTo(0,myCanvas.height) ctx.closePath() ctx.fill() ctx.stroke() ctx.restore() } } } MouseArea { anchors.fill: parent onWheel: { if (true ) { myScrollView.scaleFactor += 0.2 * wheel.angleDelta.y / 120; if (myScrollView.scaleFactor < 0) { myScrollView.scaleFactor = 0; } console.log(myScrollView.scaleFactor) } } }
}
"In this application when you scroll (zoom in) for a while, the error occurs and the view is filled with "blue" (#0000FF).
I am using Canvas in my application. I also tried using QQuickPaintedtem or QQuickItem.
With QQuickPaintedtem I still have the bug.
With QQuickItem I do not have the bug no more but the render is very slow.
Besides, I find Canvas convenient in order to draw, I would appreciate to keep using them.Does the problem come from the update/requestPaint method call on a wheel event?
Is there any other solution in order to implement my zoom function?Regards,
-
Hi @f.serreau
I have tested your example, and it works correctly with no errors.
I tested it on Windows 10 (Fall Update), MS VS2017 and Qt 5.11.0.