QPainterPath和线的交点(通过x查找QPainterPath y) [英] Intersection point of QPainterPath and line (find QPainterPath y by x)

查看:827
本文介绍了QPainterPath和线的交点(通过x查找QPainterPath y)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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?

推荐答案

根据文档:

QPainterPath QPainterPath :: intersected(const QPainterPath& p)const

返回一条路径,该路径是该路径的填充区域和p的填充区域的交集. 由于进行贝塞尔曲线相交的数值不稳定,贝塞尔曲线可能会展平为线段.

QPainterPath QPainterPath::intersected ( const QPainterPath & p ) const

Returns a path which is the intersection of this path's fill area and p's fill area. Bezier curves may be flattened to line segments due to numerical instability of doing bezier curve intersections.

由于您的行没有填充区域,因此此功能似乎对您不起作用.

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:

QList QGraphicsScene :: collidingItems(const QGraphicsItem * item,Qt :: ItemSelectionMode mode = Qt :: IntersectsItemShape)const

返回与项目碰撞的所有项目的列表.冲突是通过调用QGraphicsItem :: collidesWithItem();确定的.碰撞检测由模式决定.默认情况下,将返回形状与项目相交或包含在项目形状内的所有项目. 这些项目以降序堆叠的顺序返回(即,列表中的第一个项目是最上面的项目,最后一个项目是最下面的项目).

QList QGraphicsScene::collidingItems ( const QGraphicsItem * item, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape ) const

Returns a list of all items that collide with item. Collisions are determined by calling QGraphicsItem::collidesWithItem(); the collision detection is determined by mode. By default, all items whose shape intersects item or is contained inside item's shape are returned. The items are returned in descending stacking order (i.e., the first item in the list is the uppermost item, and the last item is the lowermost item).

不幸的是,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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆