QGraphicsItem :: boundingRect()是否应包含子边界矩形? [英] Should QGraphicsItem::boundingRect() include child bounding rects?

查看:99
本文介绍了QGraphicsItem :: boundingRect()是否应包含子边界矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌搜索建议这样做.>

但是dragdroprobot 示例实现(在父机器人对象)建议不要这样做:

  QRectF Robot :: boundingRect()const{返回QRectF();} 

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

解决方案

根据suggests that it should.

But the dragdroprobot example implementation (on the parent Robot object) suggests not:

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

Which is correct, or is there something more subtle going on?

解决方案

Child items are painted directly by the scene not by the parent, and according to the documentation about boundingRect():

QGraphicsView uses this to determine whether the item requires redrawing.

So, if there is no drawing to do in the parent, there is no need to return a non-null bounding rectangle, even if the parent has child items. And if there is some drawing in the parent, it only needs to contain its own bounding rectangle.

这篇关于QGraphicsItem :: boundingRect()是否应包含子边界矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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