The intersection point of QPainterPath and string (find QPainterPath y by x)

I have a QPainterPath. I need to find the y coordinate of QPainterPath using x.

I found the intersected () method in QPainterPath. So, I created a new QPainterPath, which is the line from the left to the right edge of my x bounding box, to find the point as a result of the intersection.

Method

intersects () returns true. But intersected () returns an empty path.

Everything works if I use rect with height = 1 instead of a string.

Maybe you better understand how to find the intersection of QPainterPath with a line?

+4
source share
1 answer

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.

+2
source

Source: https://habr.com/ru/post/948894/


All Articles