Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Draw and drag many simple items in QGraphicsView



  • I am drawing many (1000+) simple colored squares in a QGraphicsView.
    I have implemented functions to select them all and drag them.

    But when the number of sleeted squares is large, the drag is very slow.
    I have profiled my program and checked some relative posts. It suggests that the reason is because every item that is dragged is repainted every time and costs a lot of time.

    A similar example is the 400000 chips example. When you select 500+ chips and drag them, it is very slow.

    Is there any way to improve the performance? Like cache the scene into pixmap? But I did not find any related function to cache the whole scene?


  • Moderators

    yes exactly, caching is almost always a good idea.
    Use QGraphicsScene::render() to paint directly to a QPixmap. But i guess it would be enough to only draw a small area (and a add a nice fade-out effect, etc.) instead of painting the whole scene.

    If this is really the cause for the performance problem.


Log in to reply