javascript - QML Canvas - Why is the requestPaint() function not calling the paint? -
reproducible example:
here have drawn beizer curve qml canvas. paint gets called once though change start , end values explicitly causing signal generate.
see output too. why requestpaint() function doesn't call paint?
test.qml
import qtquick 2.4 canvas { id: head; width: parent.width; height: parent.height property int curvestartx: -1 property int curvestarty: -1 property int curveendx: -1 property int curveendy: -1 rectangle { id: startcontrolpoint x: head.curvestartx; y: head.curvestarty; width: 15; height: 15; color: "red"; radius: 100 onxchanged: { console.log("start called x1"); head.requestpaint(); console.log("start called x2") } onychanged: { console.log("start called y1"); head.requestpaint(); console.log("start called y2") } } rectangle { id: endcontrolpoint x: head.curveendx; y: head.curveendy; width: 15; height: 15; color: "red"; radius: 100 onxchanged: head.requestpaint () onychanged: head.requestpaint () } onpaint: { console.log ("paint got called!") var ctx = getcontext ("2d"); ctx.beginpath (); ctx.clearrect (0, 0, head.height, head.width); ctx.fill (); ctx.strokestyle = head.curvecolor ctx.linewidth = 2; ctx.beginpath (); // start point of curve. ctx.moveto (head.curvestartx, head.curvestarty) ctx.beziercurveto (startcontrolpoint.x, startcontrolpoint.y, endcontrolpoint.x, endcontrolpoint.y, head.curveendx, head.curveendy); ctx.stroke (); } }
main.qml
import qtquick 2.4 import qtquick.window 2.2 window { visible: true height: 500 width: 500 test { id: } component.oncompleted: { what.curvestartx = 0 what.curvestarty = 0 what.curveendx = 50 what.curveendy = 50 ///////////////////////////////////////// what.curvestartx = 10 what.curvestarty = 10 what.curveendx = 60 what.curveendy = 60 } }
output:
qml debugging enabled. use in safe environment. qml: start called x1 qml: start called x2 qml: start called y1 qml: start called y2 qml: start called x1 qml: start called x2 qml: start called y1 qml: start called y2 qml: start called x1 qml: start called x2 qml: start called y1 qml: start called y2 qml: paint got called!
requestpaint()
requests canvas
repainted. if take qquickcanvasitem::requestpaint()
:
void qquickcanvasitem::requestpaint() { markdirty(d_func()->canvaswindow); }
you can see calls qquickcanvasitem::markdirty()
:
void qquickcanvasitem::markdirty(const qrectf& rect) { q_d(qquickcanvasitem); if (!d->available) return; d->dirtyrect |= rect; polish(); }
which in turn calls qquickitem::polish()
:
void qquickitem::polish() { q_d(qquickitem); if (!d->polishscheduled) { d->polishscheduled = true; if (d->window) { qquickwindowprivate *p = qquickwindowprivate::get(d->window); bool maybeupdate = p->itemstopolish.isempty(); p->itemstopolish.insert(this); if (maybeupdate) d->window->maybeupdate(); } } }
so paint()
signal emitted whenever scenegraph decides ready. signal emitted in qquickcanvasitem::updatepolish()
.
Comments
Post a Comment