请教QT中界面的显示闪烁的消除问题
小弟刚刚学QT,做了一个界面,中间有一部分是字符串显示的,用是QScrollView累,大概显示200行记录,只是要一秒钟刷新一次(增加一条),结果在刷新的时候会出现闪烁问题,代码如下,请高手指点一下,有没有可一消除闪烁的方法,好象mfc中有
void MyCustomWidget::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
{
// The Background
if ( !bg.isNull() )
{
int rowheight=bg.height();
int toprow=cy/rowheight;
int bottomrow=(cy+ch+rowheight-1)/rowheight;
int colwidth=bg.width();
int leftcol=cx/colwidth;
int rightcol=(cx+cw+colwidth-1)/colwidth;
for (int r=toprow; r<=bottomrow; r++)
{
int py=r*rowheight;
for (int c=leftcol; c<=rightcol; c++)
{
int px=c*colwidth;
p->drawPixmap(px, py, bg);
}
}
return;
}
else
{
p->fillRect(cx, cy, cw, ch, QColor(255,255,255));
}
{
QFontMetrics fm=p->fontMetrics();
p->setPen(red);
int rowheight=fm.lineSpacing();
int toprow=cy/rowheight;
int bottomrow=(cy+ch+rowheight-1)/rowheight;
int colwidth=fm.width("00000,000000 ")+3;
int leftcol=cx/colwidth;
int rightcol=(cx+cw+colwidth-1)/colwidth;
QString str;
for (int r=toprow; r<=bottomrow; r++) {
if(r >= 200)
break;
int py=r*rowheight;
int px=0;
if(start == NULL)
break;
p->drawText(0, py+fm.ascent(), start[r]);
}
}
}