【问题标题】:Understanding Interaction between QGraphicsItem boundingRect and shape Methods了解 QGraphicsItem boundingRect 和 shape 方法之间的交互
【发布时间】:2015-12-10 18:22:21
【问题描述】:

我对 Qt 的 QGraphicsScene 非常有经验,但我希望有人能澄清有关 QGraphicsItemboundingRectshape 方法的细节。据我所知,文档没有解决这个具体问题。

我有一种情况,我需要为许多复杂路径计算一个形状,该形状包括一个轻微的缓冲区,以使用户更容易点击和选择路径。我正在使用QPainterPathStroker,它很贵。我目前正在尝试延迟形状计算,直到实际调用 shape 方法,这有助于提高性能。

现在的情况是边界矩形是从路径边界加上任何笔宽度计算出来的,这对于封闭绘制区域是正确的。但是在计算shape的结果时,由于选择缓冲区大于绘图区域,所以它大于边界矩形。

这是个问题吗? boundingRect 不包含 shape 结果区域是否可以接受?还是在重新计算shape时需要重新计算boundingRect

谢谢。

道格·麦格拉思

【问题讨论】:

    标签: c++ qt qgraphicsitem qgraphicsscene


    【解决方案1】:

    QGraphicsItem::shape 用于对象碰撞检测、命中测试和了解鼠标点击发生的位置。

    相比之下,QGraphicsItem::boundingRect 用于绘制对象,知道对象何时离开屏幕或被遮挡。正如 boundingRect 的文档所述:-

    QGraphicsView 使用它来确定项目是否需要重绘。

    因此,boundingRect 应该完全包含从形状函数返回的QPainterPath

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 2012-09-06
      • 2016-11-11
      相关资源
      最近更新 更多