Unsolved QGraphicsItem paint event called continually during QWidget::event loop
-
So now it's working as you want ?
-
No the paint method is still being called repeatedly for each rectangle in the scene, which is time consuming. I only want paint to be called when something changes in the rectangle like when it is moved or the color is changed. It may be that I am misunderstanding when the paint method is triggered. Is it supposed to be triggered at every QWidget event? Because that is what seems to be happening right now.
-
One other detail, you are not calling the correct base class implementation of MainWindow.
Also, do you really need Frame ? Looks like you could put the QGraphicsView directly as central widget, no ?
-
No the QFrame is not necessary, we will need to refactor that. I'm not sure what you mean by not calling the correct base class implementation. Are you referring to the QMainWindow constructor?
-
In
MainWindow::event
, you are not callingQMainWindow::event
butQWidget::event
. -
Oh yes that is true. I tried switching it to QMainWindow::event but the result was the same
-
What else are you doing in your application ?
-
We have a palette of icons in a dock widget that the user can add into the scene, copy, paste and delete. Each graphics item has a proxy widget that holds properties for the item. The items are rectangles and lines that connect between them so that moving a rectangle should move the lines that are connected to it. I want the items to update at a reasonable event, for example a mouse release event, instead of repeatedly like they doing now which is causing some lag. Basically I want to install an event filter, but am first trying to understand why all QMainWindow events are triggering a graphics item paint.
-
By proxy do you mean you have QProxyGraphicsProxyWidget ?
-
yes that's it
-
How many are they at once on your scene ?
-
There's no limit to how many can be in the scene and the scenes are likely to get complicated . Most likely there will be between ~10 and ~50 items at a time.
-
Are you still experiencing that if you avoid the proxy widgets ?
-
Yes we are
-
This post is deleted! -
Is the code accessible somewhere to be tested ?
-
Hi sorry for the late response. We figured out the problem. Within the paint function of the rectangle we were updating the line and this was causing an infinite paint loop. Thank you for your help!
-
Glad you found out and thanks for sharing !
Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)