问题描述
我有QPainterPath.我需要通过x查找QPainterPath的y坐标.
I have QPainterPath. I need to find y coordinate of QPainterPath by x.
我在QPainterPath中找到了intersected()方法.因此,我创建了新的QPainterPath,它是路径边界rect的从左到右沿x坐标的线,以找到作为交集结果的点.
I found intersected() method in QPainterPath. So, I created new QPainterPath, which is line from left to right edge of my path's bounding rect with x coordinate, to find point as result of intersection.
intersects()方法返回true.但是intersected()返回空路径.
intersects() method returns true. But intersected() returns empty path.
一切正常,如果我使用height = 1而不是line的rect.
Everything works If I use rect with height = 1 instead of line.
也许您有一个更好的主意,如何找到QPainterPath与线的交点?
Maybe you have a better idea how to find intersection of QPainterPath with line?
推荐答案
根据文档:
由于您的行没有填充区域,因此此功能似乎对您不起作用.
Since your line has no fill area, it would seem like this function would not work for you.
如果使用QGraphicsScene来显示QPainterPath,则可以使用collidingItems方法:
If you are using a QGraphicsScene to display your QPainterPath you can use the method collidingItems:
不幸的是,QPainter似乎没有相同的功能.我认为您创建长矩形的方法可能是一种更简单的方法.
Unfortunately, QPainter does not seem to have the same function. I think that your method of creating a long rectangle might be an easier way of doing this.
这篇关于QPainterPath和线的交点(通过x查找QPainterPath y)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!