I have an application that allows the user to draw arrows between boxes using the QGraphics items, views, etc. The arrows are a line with an arrow head drawn on the right hand side, with text at the base of the arrow (non arrow side).

The problem is that the bounding rectangles overlap a lot when the arrows intersect or become near each other. What is the best way to determine what arrow is closest to the mouse click point? My current method is "ok" in that it works most of the time, but it can be confused and selects the wrong arrow. The method I use is to create a line (not on the screen) from the arrow head to the click point and from the arrow tail to the click point, combine those line lengths and do the same for each arrow found under the click point. The arrow with the least combined length is usually the closest, so I change its color (select it).

In a nutshell, if a bunch of bounding rectangles intersect, what is the best way to determine which arrow is actually closest to the clicked point on the screen (the bounding rectangles are larger than the line so that they can fit the arrow head and text)?