eperfa
7th April 2011, 00:36
Hi,
I would like to be able to make an item (let's say a rectangle) flash at constant high frequencies on the screen. I know this isn't something that can be solved prefectly (due to the scheduler of the OS, imperfect timing, etc.) but I would like to get fairly good results.
The objects to be drawn are extremely simple, so I guess that most of the time is spent on actually redrawing the image on the screen. For this reason I'd like to ask your opinion on what you think is the fastest method of performing this.
Right now I've come up with something like this:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
rect = scene.addRect(QRectF(0, 0, 100, 100), QPen(), Qt::black);
ui->graphicsView->setViewport(new QGLWidget);
ui->graphicsView->setScene(&scene);
ui->graphicsView->show();
timeLine = new QTimeLine(40000, this);
timeLine->setCurveShape(QTimeLine::LinearCurve);
timeLine->setFrameRange(0, 1000);
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(updateRect(int)));
timeLine->start();
}
void MainWindow::updateRect(int frame)
{
if (frame % 2)
{
this->rect->setBrush(Qt::blue);
}
else
{
this->rect->setBrush(Qt::black);
}
this->rect->update();
}
This works, but it can be clearly seen that redrawing isn't done "instantaneously". Searching on the forum I've found that OpenGL should be used as the viewport renderer, and it did actually make a difference, but I think this could still be improved.
This is something that is really difficult to measure (I don't really know if this could be measured at all), that's why I ask you to share your thoughts on this matter. If you have something in your mind that you think could significantly improve the drawing performance (throwing out Graphics View in favor of a simple QWidget? using two fixed QPixmaps?), please share it with me.
Thanks,
Adam
I would like to be able to make an item (let's say a rectangle) flash at constant high frequencies on the screen. I know this isn't something that can be solved prefectly (due to the scheduler of the OS, imperfect timing, etc.) but I would like to get fairly good results.
The objects to be drawn are extremely simple, so I guess that most of the time is spent on actually redrawing the image on the screen. For this reason I'd like to ask your opinion on what you think is the fastest method of performing this.
Right now I've come up with something like this:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
rect = scene.addRect(QRectF(0, 0, 100, 100), QPen(), Qt::black);
ui->graphicsView->setViewport(new QGLWidget);
ui->graphicsView->setScene(&scene);
ui->graphicsView->show();
timeLine = new QTimeLine(40000, this);
timeLine->setCurveShape(QTimeLine::LinearCurve);
timeLine->setFrameRange(0, 1000);
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(updateRect(int)));
timeLine->start();
}
void MainWindow::updateRect(int frame)
{
if (frame % 2)
{
this->rect->setBrush(Qt::blue);
}
else
{
this->rect->setBrush(Qt::black);
}
this->rect->update();
}
This works, but it can be clearly seen that redrawing isn't done "instantaneously". Searching on the forum I've found that OpenGL should be used as the viewport renderer, and it did actually make a difference, but I think this could still be improved.
This is something that is really difficult to measure (I don't really know if this could be measured at all), that's why I ask you to share your thoughts on this matter. If you have something in your mind that you think could significantly improve the drawing performance (throwing out Graphics View in favor of a simple QWidget? using two fixed QPixmaps?), please share it with me.
Thanks,
Adam