QGraphicsView, QGraphicsPath - find closest path ?
-
Hi
The easy solution is to use the items bounding box and
loop over the items and check if mouse click was close to one of them.
If the paths can be overlapped, its much more complicated. -
-
@mrjj said in QGraphicsView, QGraphicsPath - find closest path ?:
@Dariusz
you loop over the items and ask contain(clickpos)
and if yes, thats the one?
Or am i missing something?What happens if 3+ items return true. How would I know which one is closer ?
-
Also another problem with path.contains that I find is that the contains would use this as check area >
https://doc.qt.io/archives/qt-4.8/images/graphicsview-pathitem.png
Which means that the shape can be bigger/inaccurate comparing to the selection location... I think I will need to do some math and create another method for path click intersection.Ok I sorta managed to "fix" it... I ended up creating a forward and then reverse path during selection process. So that the path is a closed - precise - shape. This way I can get proper click detection, I still cant compute which path is closer, but at least selection works properly now.