c++ - QGraphicsItem::boundingRect() 是否应该包含子边界矩形?

标签 c++ qt qgraphicsscene

谷歌搜索 suggests that it should .

但是拖放机器人 example implementation (在父 Robot 对象上)建议不要:

QRectF Robot::boundingRect() const
{
    return QRectF();
}

哪个是正确的,还是有更微妙的事情发生?

最佳答案

子项由场景直接绘制,而不是由父项绘制,并根据 the documentation about boundingRect() :

QGraphicsView uses this to determine whether the item requires redrawing.

因此,如果父项中没有要绘制的内容,则无需返回非空边界矩形,即使父项中有子项也是如此。 如果父级中有一些绘图,它只需要包含自己的边界矩形。

关于c++ - QGraphicsItem::boundingRect() 是否应该包含子边界矩形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7448321/

相关文章:

c++ - 检测单元测试中的特定函数调用

c++ -/usr/bin/ld : cannot find -lGL (Ubuntu 14. 04)

c++ - 如何在 GoogleTest 中使用 QTimers

c++ - QGraphicsView fitInView方法: resizing problems

python - Qt中实现一维拖动操作

C++ 虚拟继承、虚拟析构函数和 dynamic_cast<void*>

c++ - 复制构造函数问题

c++ - 插槽未被使用

c++ - 自动协变类推导

来自麦克风的连续语音识别 pocketsphinx