我做了一个仪器界面,需要在界面上画出一组随即波形,为了呈现一种动态的形式,加了一个定时器定期的repaint,可是问题是,无论我怎么设置定时器的start(),程序实际运行的结果,我发现都是一秒钟重画一次。我用的是qt-2.3.7,硬件平台是arm9的s3c2410。
把部分代码贴出来,希望大家指点迷津,谢谢大家!
MyMainWindow::MyMainWindow()
{
screentimer = new QTimer(this);
setBackgroundColor(QColor(80,80,80));
setBackgroundMode(NoBackground);
setGeometry(0,0,320,240);
setupbutton = new QPushButton("Setup",this);
setupbutton->setGeometry(0,0,40,25);
filebutton = new QPushButton("File",this);
filebutton->setGeometry(41,0,40,25);
resultbutton = new QPushButton("Result",this);
resultbutton->setGeometry(82,0,40,25);
helpbutton = new QPushButton("Help",this);
helpbutton->setGeometry(123,0,40,25);
connect(screentimer,SIGNAL(timeout()),this,SLOT(repaint()));
screentimer->start(50);
}
void MyMainWindow::paintEvent(QPaintEvent *)
{
int i;
int value;
int bak_value=130;
int w=this->width();
int h=this->height();
QPen exborderpen(blue,2,SolidLine);
QPen inblankpen(black,1,DotLine);
QPen datapen(cyan,1,SolidLine);
QPixmap pm(w,h);
pm.fill(white);
srand(time(NULL));
QPainter paint(&pm);
paint.setPen(exborderpen);
paint.drawRect(8,30,304,200);
paint.setPen(inblankpen);
for(i=1;i<8;i++)
{
paint.drawLine(10,30+i*25,309,30+i*25);
}
for(i=1;i<12;i++)
{
paint.drawLine(10+i*25,30,10+i*25,229);
}
paint.setPen(datapen);
for(i=0;i<299;i++)
{
value=rand()%50+105;
paint.drawLine(10+i,bak_value,11+i,value);
bak_value = value;
}
paint.end();
QPainter painter(this);
painter.drawPixmap(0,0,pm,0,0);
}