QPainterPath stroke artifacts

I am putting together a QPainterPath with text, then I'm drawing it, first with QPainter::strokePath, then with QPainter::fillPath. However, the stroke exhibits artefacts, as shown in the image. Anything I am doing wrong/how to prevent this? Should I report it as a bug? Example

1 answer

  • answered 2018-07-11 21:50 Danol

    I've found out that instead of using strokePath and fillPath, the following code works without artefacts and is even faster to render:

    if(outlineEnabled) {
        p.setBrush(Qt::NoBrush);
        p.setPen(QPen(outlineColor, outlineWidth/scaleFactor, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
        for(const auto &polygon : path.toSubpathPolygons())
            p.drawPolygon(polygon, Qt::OddEvenFill);
    }
    
    p.setBrush(color);
    p.setPen(Qt::NoPen);
    for(const auto &polygon : path.toFillPolygons())
        p.drawPolygon(polygon, Qt::OddEvenFill);