2

I am trying to draw a polygon with multiple holes in them with QPainter (QT5.8, win64). I am using the following code:

QPainter pm(&image);
QPen p(Qt::gray, 2);
p.setCosmetic(true);
pm.setPen(p);   
pm.setBrush(QBrush(color));

QPainterPath pap;

pap.addPolygon(pObject->getOuterGeometryPolyF());

for (int i = 0; i < (int)pObject->m_InnerGeometry.size(); i++)
{
    QPainterPath papInner;
    papInner.addPolygon(pObject->getInnerGeometryPolyF(i));
    pap = pap.subtracted(papInner);
}

pm.drawPath(pap);

But it will only show one hole (see image):

enter image description here

Can someone provide me with an example of how to draw a polygon with multiple holes on it? The documentation is not clear on this point.

apalomer
  • 1,895
  • 14
  • 36
Richy
  • 534
  • 4
  • 13
  • I just found out that it has to do with the order of the point in the polygon (clockwise, not clockwise). Still trying to find a rule for this. – Richy Apr 11 '20 at 10:26

1 Answers1

2

I will answer my own question...

It all depends on the rotation order of the polygon (clockwise or anti clockwise). The holes should have opposite rotation order of the outer polygon to make it work flawlessly.

So for example outer polygon = clockwise, inner polygons should have anti-clockwise order. If this is not the case, reverse the order.

Richy
  • 534
  • 4
  • 13