PDA

View Full Version : QGraphicsView framework performance



saifulkhan
28th March 2013, 00:03
Dear All,

I am using qt 5.0.1 in windows. I am creating 200k+ custom QGraphicsItem. I have added basic functionalists in these custom items, like mouse hover, mouse click etc.. This items are static. But on top of these items I add some items (200 max) which animates (different property animation, scale, opacity etc).
When I add those items in the scene it become extremely slow, in a relatively powerful workstation.




QGraphicsScene *scene = new QGraphicsScene();
scene->setSceneRect(0, 0, width, height);
scene->setBackgroundBrush(Qt::darkGray);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);

QGraphicsView *view = new QGraphicsView( scene );
view->setRenderHint(QPainter::Antialiasing, false);
view->setResizeAnchor(QGraphicsView::AnchorViewCenter);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
view->resize( width, height );
view->setOptimizationFlags(QGraphicsView::DontSavePainte rState);
view->setViewportUpdateMode( QGraphicsView::SmartViewportUpdate);
view->setTransformationAnchor(QGraphicsView::AnchorUnder Mouse);
view->setCacheMode(QGraphicsView::CacheBackground);
view->setViewportUpdateMode( QGraphicsView::FullViewportUpdate);
view->show();



I have tried the following, but it makes the rendered view extremely bad, as it seems to enable antialiasing, but I need some pixel label precision.



view->setViewport(new QGLWidget( QGLFormat()));



Am I missing some important Qt programming tricks? Please suggest. I can post the code, or explain more if in case please let me know. Thanks in advance.

saifulkhan
28th March 2013, 04:01
May be reducing the frame rate of QPropertyAnimation will help, is there any way to do so?

wysota
28th March 2013, 07:45
It's hard to help without knowing details about your scene. If animating items cover a relatively small portion of the view then I'd disable full viewport update. If "static" items are indeed static and not interactive, I'd replace them with drawBackground. If the scene is not interactive, I'd disable interactivity on the view. I'd also enable caching for the items. That's something to start experimenting with.

saifulkhan
28th March 2013, 12:43
Thanks for this nice tricks. Is there any way to set those static custom QGraphicsItems as a background of the view? Currently I add these static items in the same scene where I add those animated items. But for time being I can afford to remove interaction from the static items, though ideally its not the case.

I have added the following:

view->setViewportUpdateMode( QGraphicsView::MinimalViewportUpdate );

Enable item caching: setCacheMode( QGraphicsItem :: DeviceCoordinateCache, bound.size().toSize() );

wysota
28th March 2013, 13:33
Is there any way to set those static custom QGraphicsItems as a background of the view?
You'd have to draw them yourself. If that's too complex for you then at least enable caching for them.