Hi
I read in documentation to the Graphics View Framework that visualization of even millions of items performs real-time. To check it I put a little experiment. I made just 50000 items of QGraphicsEllipseItem(qrand() % 500, qrand() % 500, 4, 4) and tried to move it chaotically every half of a second. QGLWidget was selected as viewport. Code of the move() slot to the timer's timeout() signal looked like this:
void Visview::move()
{
for (int i = 0; i < 50000; i++)
{
elems[i]->setPos(elems[i]->x() + (qrand() % 20) - 10,
elems[i]->y() + (qrand() % 20) - 10);
}
}
void Visview::move()
{
for (int i = 0; i < 50000; i++)
{
elems[i]->setPos(elems[i]->x() + (qrand() % 20) - 10,
elems[i]->y() + (qrand() % 20) - 10);
}
}
To copy to clipboard, switch view to plain text mode
For timer timeout=500 ms it worked extremely slow: about 20 secs to one step of movement. I achieved a big performance improvement by adding
scene.update(-500, -500, 1000, 1000);
scene.update(-500, -500, 1000, 1000);
To copy to clipboard, switch view to plain text mode
to the end of the function. But speed of working is still unsatisfactory to me. About 1.5-2 secs to step, and about 8 secs to first step of movement. I found that the loop with new positions setting
for (int i = 0; i < 50000; i++)
{
elems[i]->setPos(elems[i]->x() + (qrand() % 20) - 10,
elems[i]->y() + (qrand() % 20) - 10);
}
for (int i = 0; i < 50000; i++)
{
elems[i]->setPos(elems[i]->x() + (qrand() % 20) - 10,
elems[i]->y() + (qrand() % 20) - 10);
}
To copy to clipboard, switch view to plain text mode
takes about 600 ms to step. Can I make this loop faster somehow?
PS. I learned source code of the setPos and found it call update function of the scene. But if internal flag updateAll is set to true update() does nothing. To set updateAll to true it's enough to call scene.update(QRect()). I tried to do so before loop, but it took no effect.
My Qt version is 4.6.0.
Thank you.
Bookmarks