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

Christian Ehrlicher Ch.Ehrlicher at gmx.de
Fri Apr 26 21:52:48 CEST 2024


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");

This code should draw a small down arrow (e.g. for a QPushButton with a
QMenu attached) and should look similar to this:

   0123456
0
1  XXXXX
2   XXX
3   XXX
4    X
5    X
6

But the outcome is this:

   0123456
0
1  XXXX
2   XX
3   XX
4
5
6

Setting a non-cosmetic pen at least result in painting of all three
corners but gives a non-symmetric triangle:

   0123456
0
1  XXXXX
2  XXXX
3   XXX
4   XX
5    X
6

I've no idea how to draw this triangle the way I want (and everyone is
satisfied with the outcome). Do you have any ideas?


Thx,
Christian



More information about the Development mailing list