According to the documentation:
QPainterPath QPainterPath :: intersected (const QPainterPath and p) const
Returns the path that is the intersection of the path fill area and the fill area. Bezier curves can be flattened to line segments due to the numerical instability of the intersections of the Bezier curve.
Since your line does not have a padding area, it looks like this function will not work for you.
If you use QGraphicsScene to display QPainterPath, you can use the collidingItems method:
QList QGraphicsScene :: collidingItems (const QGraphicsItem * item, Qt :: ItemSelectionMode mode = Qt :: IntersectsItemShape) const
Returns a list of all elements that collide with an element. Collisions are determined by calling QGraphicsItem :: collidesWithItem (); collision detection is determined by mode. By default, all elements whose form intersects the element or is contained within the form of the element are returned. Items are returned in descending order of stacks (i.e., the first item in the list is the topmost item, and the last item is the lowest item).
Unfortunately, QPainter does not seem to have the same function. I think your method of creating a long rectangle might be an easier way to do this.
source share