将QGraphicsItem的移动区域限制在多边形区域内
Restrict movement area of QGraphicsItem inside of polygon area
我试图限制QGraphicsItem在从具有任意复杂形状(而非正方形(的QGraphicsPathItem继承的父对象内部的移动。
据我所知,我应该提取移动对象的每个点,并检查它们中的每个点是否都不包含在父QPainterPath中。然后将父QPainterPath拆分为小的矩形多边形,并限制每个子多边形的边界框中的移动区域。
所以,我想知道是否还有其他选择。谢谢
如果QGraphicsPathItem仍在QGraphicsPathItem中,则可以检查QGraphicsItem移动事件。
检查本身,您可以使用以下QGraphicsItem方法:
bool QGraphicsItem::collidesWithItem(const QGraphicsItem * other, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const
为了确保该项仍然完全封闭在其父项内,请将模式设置为Qt::ContainsItemShape
如果为false,则将QGraphicsItem返回到其先前位置
EDIT:如果QGraphicsItems形状在其他QGraphicsIitems形状内,而不是在其边界框内,则此检查返回。
相关文章:
- 计算缩放多边形的比例,得到给定的多边形面积
- 将QGraphicsItem的移动区域限制在多边形区域内
- 有没有一种优雅而快速的方法来测试整数中的 1 位是否位于连续区域
- 重新排列单线以形成闭合多边形?
- 提升几何体:C++并集多个多边形
- 在 Linux 中存储区域设置名称的缓冲区大小应该是多少?
- 在 QT C++中绘制/操作多边形
- Maya API C++:从多边形获取材质
- 两个连续的 OpenMP 并行区域会相互减慢速度
- 添加带有提升的多边形::p奥利贡不编译?
- 提升区域设置规范化带状字符,但不规范化重音
- 使用 C++在 OpenGL 中对 3D 多边形进行纹理处理
- 使用 C++在 OpenGL 中移动自动旋转的 3D 多边形
- 如何使用增强::几何计算多边形的旋转固体体积?
- 我的主窗口在创建时或单击更新区域时是否会收到编辑控件?
- 我可以将新的 std::tuple 放入内存映射区域,并在以后读回吗?
- 英特尔将指令存储在重叠的内存区域
- 如何给主窗口区域DKGRAY_BRUSH?
- openCV中2个多边形的相交区域
- 将空间分割为多边形区域,并给定一组点的沃罗尼近似