PDA

View Full Version : QGraphicsView and QGraphicsScene speeds



jnk5y
19th October 2006, 02:01
Hello all,

I am using QGraphicsView and QGraphicsScene to display thousands of points from a database.

Collecting the points from the database takes about 2 seconds but when i try to display them on a scene by using:

QGraphicsItem *item = new QGraphicsRectItem (x,y,1,1);
SampleScene->addItem(item);

it takes about 10 seconds to load the rectangles and then when i move the scene in the view it is very sluggish and takes a while to refresh.

Any ideas on making this faster to display?
Any hints or tips on using QGraphicsView to it's maximum potential?

John

wysota
19th October 2006, 10:30
If you could post your code here, it would be easier to solve your problem. The 40000 chips demo loads 40000 items almost instantly and handles them real time in four views, so unless you are using more than millions of items, it shouldn't be sluggish (when run on a decent machine, of course).

jnk5y
20th October 2006, 07:13
Ok I have a dialog with a QGraphicsView inside.
In my header i have QGraphicsScene *SampleScene;



SampleScene = new QGraphicsScene;

query.exec( "SELECT x,y FROM samples;" );

while( query.next() )
{
QGraphicsItem *item = new QGraphicsRectItem (
( minX - query.value(0).toDouble() ) * -scaleX, ( maxY - query.value(1).toDouble() ) * scaleY, 5, 5 );

SampleScene->addItem(item);
}

ui.graphicsView->setRenderHints( QPainter::Antialiasing );
ui.graphicsView->setScene(SampleScene);


I would prefer dots rather than squares and should be easier to draw. I have tried ui.graphicsView->setUpdatesEnabled(false) which helped slightly but still is very slow. I have also tried QGraphicItemsGroup which I have yet to get working for some reason. I would put the items into a QList of QGraphicItems and then


SampleGroup = SampleScene->createItemGroup ( list );
SampleGroup->show();

But I could never see the points. I have studied the 40000 chips example and have also implemented a custom QGraphicsItem which helped slightly in speed. Everything else looks similar to the chips example but much slower.