Search code examples
c++qtqpainterself-intersectionqpainterpath

find the lines cross while draw free path using QPainterPath


I'm implementing the free-form style drawing for drawing a free path using the mouse press and move with Qpainter QPainterpath

Now i have to detect when exactly the drawn path crossed or intersects with the other. how i can identify when the lines crossed each other at some point and give warning to the user.

enter image description here


Solution

  • Qt API does not have this capability to tell that if a path composed of different elements intersect in a point or not. You should check it by your self. When the path is finished, compare piece-wise segments of the path using QPainterPath::​intersects function. The elements could be accessed via QPainterPath::​elementAt(int index).