Qt drawPolygon with Qt::NoBrush, still being filled....
I'm using Qt 5.9.1, I am drawing two polygon's one on top of the other with a pen with Qt::NoBrush, but the interior is still being filled in, semi opaque but filled....why?
Pen pnOutline; pnOutline.setBrush(Qt::NoBrush); pnOutline.setColor(clrBorder); pnOutline.setWidth(3); pobjPainter->setPen(pnOutline); pobjPainter->drawPolygon(plyBorder, sizeof(plyBorder) / sizeof(plyBorder)); pnOutline.setColor(clrOutline); pnOutline.setWidth(2); pobjPainter->setPen(pnOutline); //Edit, missed this in the original post...but it is there! pobjPainter->drawPolygon(plyOutline, sizeof(plyOutline) / sizeof(plyOutline));
What I get from this is the first polygon draw with a thick black outline and no filling, then the white polygon draw on top but with a semi-opaque filled interior.
pobjPainter->drawPolygon(plyOutline, sizeof(plyOutline) / sizeof(plyOutline));
because you just assign the new values to the pen object.
But the painter still has a copy of the old pen object.
So simply also reassign the pen to the painter, whenever you update properties of the pen.
Sorry, in the original the SetPen is there, unfortunately due to issues with the company firewall and blocking forums, I had to type it all in again, instead of simply cutting and pasting.
But evening if it was missing, this wouldn't explain why the contents of the polygon appear to be filled?
All you set is the pen's brush. This is only used to fill strokes of the pen.
The painter has it's own brush, which you have to set.
Thank you, thats fixed it, why does a painter have a brush when the pen also has a brush ?
I would have thought that setting the pen brush would set the painter...obviously wrong.
Let's say you want to draw a polygon filled red, with a wide outline filled in a gradient - black on the left turning to green on the right.
In that case you would assign a gradient brush to the pen to achieve the gradient effect, and a red brush to the painter directly to achieve the polygon fill effect.