QGraphicsScene repaint loop



  • Hi,

    I am using Qt 4.8.1 and Qt 5.2.1 on Windows 7.

    My current project is like a visual editor where you can set up several nodes and connect them with edges. It is like a visual representation of a tree structure. Both, nodes and edges, are derived from QGraphicsItem. Their user defined appearance is implemented in the paint() function. All items are placed in my GraphicsScene class, derived from QGraphicsScene.

    Now my problem is that, when I have about 100 or more items in the scene (most of the edge items intersect each other), the paint event of all items (!) is triggered in an endless loop (CPU load 100%), without any user interaction. Only when I move most of the items out of the viewport so that only a few items are visible the endless repaint stops.

    This problem occurs on both Qt versions.

    Does anyone have an idea?

    regards
    Oliver



  • Are you sure you are not forcing manually repaint() of items somewhere?
    That might lead to some hard to find loops.
    When I did back in the days the same thing I did not end up having this kind of probem. Even tho it was pyqt4



  • Not directly, but I found something which could be the reason:

    My edge items vary in size and hence boundingRect size. So I used the function prepareGeometryChange() to tell the item, that the boundingRect has changed. But unfortunately it was called within the paint() function, and so the loop was perfect, because prepareGeometryChange() is able to perform an update to the scene (if necessary) and so trigger the repaint itself.

    Thanks for the advice
    Oliver


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.