QGraphicsView framework performance
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.
Code:
scene->setSceneRect(0, 0, width, height);
scene->setBackgroundBrush(Qt::darkGray);
view
->setRenderHint
(QPainter::Antialiasing,
false);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->resize( width, height );
view
->setViewportUpdateMode
( QGraphicsView::SmartViewportUpdate);
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.
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.
Re: QGraphicsView framework performance
May be reducing the frame rate of QPropertyAnimation will help, is there any way to do so?
Re: QGraphicsView framework performance
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.
Re: QGraphicsView framework performance
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() );
Re: QGraphicsView framework performance
Quote:
Originally Posted by
saifulkhan
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.