[Interest] Canvas keeping artifacts

Jérôme Godbout jerome at bodycad.com
Wed Mar 23 22:11:24 CET 2016


You may want to clear fill with blank transparency:

ctx.fillStyle = 'rgba(0,0,0,0)';
ctx.clearRect(0,0,width,height);
ctx.fill();

for me it did the trick.

On Wed, Mar 23, 2016 at 4:54 PM, Jason H <jhihn at gmx.com> wrote:

> I have a very simple pause button:
>         Canvas {
>                 id: pauseCanvas
>                 anchors.fill: parent
>                 onWidthChanged: requestPaint()
>                 onHeightChanged: requestPaint()
>                 onPaint: {
>                         var ctx = getContext('2d');
>                         ctx.save()
>                         ctx.clearRect(0,0, width,height)
>                         ctx.fillStyle = color;
>                         ctx.rect(0.125*width, 0.05*height, 0.25*width,
> 0.90*height);
>                         ctx.fill();
>                         ctx.rect(0.625*width, 0.05*height, 0.25*width,
> 0.90*height);
>                         ctx.fill();
>                         ctx.restore();
>                 }
>         }
>
> The problem is when I resize the window (which in turn resizes the
> canvas), I get artifacts of previous draws. If the window is made larger
> (corner drag or maximize) I can see the smaller original rectangles. And
> vice-versa.
>
> How can I get Canvas to play nice?
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160323/249c95b7/attachment.html>


More information about the Interest mailing list