Paving a path only inside / outside?

Given QPainterPath , how can I stroke the path only at the inner or outer edge of the path (or left or right -side for unclosed paths)?

QPainter::strokePath() centers the pen along the path and causes the same amount of ink to fall on both sides. For a visual example of the desired effect, see the figure I made (for an SVG suggestion, not a function):

SVG proposed stroke-location example, from phrogz.net/SVG/stroke-location.svg

I do not mind if this is done using any hacking, like setting the path itself as a clipping region (for the inside) or a clipping zone (for the outside).

The goal is to fill the rounded rectangle with a fill with a low opacity, and then just pull it with a stroke with a lower opacity to simulate a two-step drop in blur. If the stroke overlaps the fill, the opacity is doubled, which leads to the destruction of the effect. Due to the complex shape, simply scaling the path will not work well, even if it can work for the circles and rectangles drawn above.

+4
source share
2 answers

Best of all, most likely QPainterPathStroker . Use it to create a new path that identifies the outline of your path. Then use QPainterPath operations, such as intersecting or subtracting between them:

 outsidePath = strokedPath.subtracted(originalPath); insidePath = strokedPath.intersected(originalPath); 
+6
source

It is best to set the blending mode to CompositionMode_Source :

 QPainter * painter; painter->setCompositionMode(QPainter::CompositionMode_Source); painter->setPen(QPen{color, stroke, ...}); painter->setBrush(QBrush{...}); QPainterPath path; path.moveTo(...); path.lineTo(...); ... // No alpha composition issues painter->fillPath(); 
0
source

All Articles