主要针对QGraphicsPathItem
一般一个复杂的封闭曲线可能是由多条简单曲线拼接而成
比如我的项目中,使用了分段bezier,每段bezier至多为二次。
每段bezier我都保存了其3个或者2个control point
于是我构造path的时候,每次都先moveTo到bezier的起点,然后quadTo或者lineTo
封闭曲线是构造完成了,但是却无法点击封闭曲线内部区域来drag曲线,找原因还找了挺久。
最后想起,moveTo函数将当前起始点移动到新的位置,然后会结束上一条subpath,开始一条新的subpath
官方说明如下:
void QPainterPath::moveTo ( const QPointF & point )
Moves the current point to the given point, implicitly starting a new subpath and closing the previous one.
这样就导致我的封闭曲线在QPainterPath中并不被认为是封闭的。于是自然也无法drag。
最后我将moveTo都去掉,问题解决。