Important: Please read the Qt Code of Conduct -

Performance issue of QGraphicsView framework when trying to draw 2000*2000 ellipse

  • Just start to play with Qt graphics. I practice by working on a project that is able to visualize a network of hundreds of thousands of nodes, and millions of connections between them.

    When handling QGraphicsScene with up to thousands of QGraphicsEllipseItem, scaling (zoom in/out on the scene) QGraphicsView is quite smooth by QGraphicsView::setMatrix(). But it gets much worse when I draw millions of ellipses in the scene, especially when I zoomed out to show all of them in the view. However, according to the "4000 chips" example in, Qt should be able to deal with large number of items nicely.

    Is there any way to alleviate the slowness issue, and possibly reducing memory consumption at the same time? I checked many other examples, search quite a lot, but couldn't find any similar case.

  • Moderators

    I don't know your particular case but one thing bothers me. A Full HD display has about 2 million pixels. If you're drawing "millions" of ellipses they either overlap heavily or are so small not to cover even a single pixel. Not to mention the connections. Unless of course you're targeting something like 4K or more...

    I think you could do some sort of filtering or a simplified view at larger scales - hide some items or group them together into "aggregating" shapes, whatever makes sense for your model, thus reducing the needed number of stuff to draw and avoiding the problem.

  • Most 2D/3D CAD or Visualization tools use strategies to draw the items to the screen. For example: to speed up the redrafting of the screen, you could consider to just show a point if the ellipses become too small, make them a diamond when a little bit bigger and an ellipse when really visible. The other strategy would be not to draw the ellipse that are outside the screen. This means re-implementing the draw function depending the zoom and the location of the ellipse.

  • You can try turning on background and item cache - if those items are non interactive then this will speed up.
    Another suggestions:

    • change aliasing
    • Use OpenGL for QGraphicsView.
    • use BSP tree (if not already)
    • group small items and add them as child to "parent item", then on parent item create QImage buffer and draw those items there, on paintEvent for "Parent item" draw only pixmap not actual items.