[Development] Issues with QPainter::drawPolygon (off by one error?)

Christian Ehrlicher Ch.Ehrlicher at gmx.de
Sun Apr 28 11:00:21 CEST 2024


Am 26.04.2024 um 22:48 schrieb Henry Skoglund:
> On 2024-04-26 21:52, Christian Ehrlicher via Development wrote:
>> Hello,
>>
>> I'm currently trying to investigate a painting problem within the
>> windowsvista / common style:
>>
>>     QImage img(7, 7, QImage::Format_ARGB32_Premultiplied);
>>     QPolygon poly{ QPoint(1, 1), {5, 1}, {3, 5} };
>>     QPainter p(&img);
>>     p.setPen(Qt::NoPen);
>>     p.setBrush(QColor(Qt::black));
>>     p.drawPolygon(poly);
>>     p.setPen(QColor(0, 255, 0, 128));
>>     p.drawPoints(poly.data(), poly.size());
>>     p.end();
>>     img.save("output.png");
>> ...
>>
> Hi, I think the QPainter draws very poorly using direct polygon paths.
> You could try going via a QPainterPath, say:
>
>     QImage img(7, 7, QImage::Format_ARGB32_Premultiplied);
>     img.fill(QColor(0, 255, 0, 128));    // to be sure the img
> contains no junk values
>     QPolygon poly{ QPoint(1, 1), {5, 1}, {3, 5} };
>     QPainter p(&img);
>     p.setPen(Qt::NoPen);
>     p.setBrush(QColor(Qt::black));
>     p.setPen(QColor(0, 255, 0, 128));
>     QPainterPath path;
>     path.addPolygon(poly);
>     p.drawPath(path);
>     p.end();
>     img.save("output.png");
>
> Rgrds Henry
>

This helped a little bit but it then fails again for other sizes. It's a
mess :(
I'm shortly before drawing the triangles pixel by pixel by myself...


Christian


More information about the Development mailing list