重绘QGraphicsView 的drawbackground
发现在debug模式下背景没问题,但是在release模式下变化窗口大小时背景颜色会变化,
如果在drawbackground中加入update,则在release模式下会闪烁
void MyGraphicsView::drawBackground(QPainter * painter, const QRectF & rect)
{
//绘制背景
int wid = this->geometry().width();
int hei = this->geometry().height();
m_ptCenter = this->mapToScene(wid / 2, hei / 2);
QPixmap pix(wid, hei);
QPainter pter(&pix);
QColor clr_white(Qt::white);
QColor clr_gray(240, 240, 240, 200);
int spacing = 15;
QColor useColor;
for (int i = 0; i <= floor(wid / spacing); ++i)
{
for (int j = 0; j <= floor(hei / spacing); ++j)
{
useColor = ((i + j) % 2 == 0 ? clr_white : clr_gray);
pter.fillRect(i*spacing, j*spacing, spacing, spacing, useColor);
}
}
painter->drawImage(rect, pix.toImage());
}
现象如下:
Debug:
release:
有哪位遇到这种现象,是什么原因