纯虚函数
[pure virtual] QRectF QGraphicsItem::boundingRect() const
的作用:
它是一个矩形框,这个框框是QGraphicsItem的外边框,打个比方,假如QGraphicsItem是一个人像,boundingRect()返回的就是相框边缘的矩形。
如下图(抱歉网上随便搜的一幅图,如有侵权请联系删除),黄色的框框表示这个boundingRect()返回的矩形,而方框里面的人物,景色,则为QGraphicsItem的内容,这个内容可以是多边形,矩形,三角形,直线等等
boundingRect()返回的这个矩形框的作用,是为了刷新里面的内容。
我们新建一个继承于QGraphicsItem的类,加到Qgraphicscene中去后,假如我们随意设置boundingRect()返回值,如0,0,100,100。 则只会刷新该固定区域。此时,如果我们的实际位置是其他,则很可能无法刷新。因此,很有必要将boundingRect()返回调整成实际物体所在位置的包含区域。
使用一个QPainterPath举例:
QRectF MyItem::boundingRect() const
{
qDebug()<<“boundingRect”;
return thisQRectF;
}
void MyItem::thisQRectF_init(