1

When using a QPen to stroke a QPainterPath, it does so in the center of the line. What I would like to do is stroke the path along the inside of the line. I have already looked at a similar question here but it did not provide a clear solution or example.

How do I stroke the inside of a QPainterPath line?

Community
  • 1
  • 1

1 Answers1

1

This is the most elegant solution I could come up with.

static QPolygonF shrinkPolygon(QPolygonF poly, qreal pixels)
{
    QPolygonF new_polygon;
    QSizeF size = poly.boundingRect().size();
    qreal x_center = size.width()/2;
    qreal y_center = size.height()/2;

    for(int x=0; x < poly.size(); x++)
    {
        QPointF point = poly.at(x);

        if(point.x() <  x_center)
        {
            point.setX(point.x()+pixels);
        }
        else
        {
            point.setX(point.x()-pixels);
        }

        if(point.y() < y_center)
        {
            point.setY(point.y()+pixels);
        }
        else
        {
            point.setY(point.y()-pixels);
        }

        new_polygon.append(point);
    }

    return new_polygon;
}