Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.6.0, 5.8.0
-
None
-
Windows 10, VS2015 64 bit
Description
In the following snippet the restore() call does not properly return the clip state to what it was prior to the save() call. It is specific to the setClipping(false) call. If I had instead changed the clip by using setClipPath() then clipping would have been restored properly.
The result is a large green square. It should have been a large red square with a smaller green square inside.
It is specific to a QImage painter. I have tried the same sequence of drawing operations on a PDF QPrinter and on QOpenGLPaintDevice and both produce the correct result.
I have reproduced the issue in 5.3, 5.6 and 5.8
QImage im2(256,256, QImage::Format_ARGB32_Premultiplied);
im2.fill(0xFF0000FF);
QPainter pt(&im2);
pt.setBrush(Qt::red);
QPainterPath cpth;
cpth.addRect(50, 50, 100, 100);
QPainterPath pth;
pth.addRect(10, 10, 236, 236);
pt.setClipPath(cpth); // Set a clipping path
pt.save(); // save state
pt.setClipping(false); // disable clipping
pt.setBrush(Qt::red);
pt.drawPath(pth);
pt.restore(); // restore state.. but clipping is still disabled
pt.setBrush(Qt::green);
pt.drawPath(pth); // red square is completely covered. Clipping should have limited this to a small part.
pt.end();
im2.save("C:\\temp
test.png", "PNG");