我在 GUI 上将 QGraphicsScene 实例设置为 QGraphicsView,启用滚动条并更新全视口。但是当我滚动我的图形视图时,我得到添加到 qgraphics 场景的项目在某些时候消失了,尽管它们被正确地添加到代码中并且预计会在滚动时显示(从 QGraphicsItem 继承的自定义类):
class CSquare : public QObject, public QGraphicsItem
paint 方法实现如下:
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
有人可以提示问题是什么,如何解决图形项不会在视图上消失?
提前致谢。