我在GUI上将QGraphicsScene实例设置为QGraphicsView,并启用滚动条和完整视图端口更新。但是,当我滚动图形视图时,添加到qgraphics场景中的项目在某个时候消失了,尽管它们在代码中添加正确,并且有望在滚动时显示(从QGraphicsItem继承的自定义类):
class CSquare : public QObject, public QGraphicsItem
油漆方法如下:
void CSquare::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
static int sz;
painter->setFont(fnt_);
painter->fillRect(this->r,this->br);
painter->drawRect(this->r);
//painter->drawText(this->p,this->txt);
if (txt == "")
return;
if (fnt_.pixelSize()>0)
sz = fnt_.pixelSize();
else
if (fnt_.pointSize()>0)
sz = fnt_.pointSize();
else
if (fnt_.pointSizeF()>0)
sz = fnt_.pointSizeF();
switch (this->al_flag)
{
case 1:
painter->drawText(this->p.x(),this->p.y(),sz*txt.size(),2*sz,Qt::AlignRight,this->txt);
break;
case 2:
//painter->drawText(this->r,Qt::AlignLeft,this->txt);
painter->drawText(this->p.x(),this->p.y(),sz*txt.size(),2*sz,Qt::AlignLeft,this->txt);
break;
case 3:
//painter->drawText(this->r,Qt::AlignCenter,this->txt);
painter->drawText(this->p.x(),this->p.y(),sz*txt.size(),2*sz,Qt::AlignCenter,this->txt);
break;
case 4:
//painter->drawText(this->r,Qt::AlignJustify,this->txt);
painter->drawText(this->p.x(),this->p.y(),sz*txt.size(),2*sz,Qt::AlignJustify,this->txt);
break;
}
}
人们可以看到他们是如何在这个视频屏幕上运行的应用程序上消失的:
https://www.box.com/s/h4h94×1avgay1crzvyzx
有人能提示问题出在哪里吗?如何解决,使图形项目不会在视图中消失?
提前谢谢。
QRectF boundingRect()const;
应该返回有效的矩形。现在我在我的项目中修复了这个问题,并将删除视频。
感谢您的关注。