Removing an area from a Path

I need draw some shapes with some sections removed, e.g. an ellipse with a vertical strip removed.

Is there a way remove a section from a Path, like the opposite of Path::addRectangle?

I just realised why this wouldn’t work - what I’m asking would break the Path in two. Still curious as to how this might be achieved using Paths.

Screenshot 2021-03-04 at 11.19.13

Is this only aesthetic or does it provide a function?

If the former, could you just draw a rectangle the same colour as the background so it looks like it breaks the ellipse in two paths.

Aesthetic only

That’s exactly what I’m doing now but it means I have to draw things in a certain order and the code is not as neat as I’d like :slight_smile:

You could use the PathFlatteningIterator, use it to draw the path manually and skip the segments you don’t need.

What about Graphics::excludeClipRegion? This won’t modify the path per se, but it should work if your goal is to simply draw the path. Just remember that this function will modify the clipping region of the graphic context, so you’ll probably need to call Graphics::saveState before using it and Graphics::restoreState afterwards if you need to draw additional stuff.

1 Like

Graphics::excludeClipRegion did the trick, thanks!