PDA

View Full Version : Painting updates



QbelcorT
26th September 2008, 06:58
Hi.
I have a QGraphicsScene with items. I have a different view depending on which 'button item' is pressed on the scene. So the view changes if an icon button is pressed.
Example : Scene view #1 has buttons and items.
Buttons:
The buttons are created from a class of it's own, call it class::button, inherits QGraphicsRectItem. This class re-implements the virtual paint function, and the buttons are painted. In this class the painting of the buttons are done, and mouse events are captured when the buttons are pressed.
Items:
The item is a polygon with a radial gradient. This is a class:: polygonitem, inherits QGraphicsPolygonItem. This class re-implements the virtual paint function, and the polygon is painted.
Problem:
When I press a button/icon on a scene, the button paint function updates the button (due to the event that causes the button to expand and retract. The button class mouse event calls 'update()' to update the button. When the update function is called, it also causes my polygon item to update. The paint function in the polygon class is also called for an update.

This functionality will slow down the button presses. I do not need the polygon repainted everytime the button is pressed. I know it's probably related to how I implemented the classes and painting. Ideas? When I call 'update()' only the button item is updated?
Thank you

wysota
26th September 2008, 09:03
If boundingRect()s of the button and the polygon intersect, the polygon will get updated. There is not much you can do about it apart from redefining the boundingRects so that they don't intersect or setting the graphicsview into QGraphicsView::NoViewportUpdate mode and do the update yourself.

QbelcorT
26th September 2008, 10:10
sorry I didn't give you more detail. No, the button items are no where near the polygon item. There is no way they will ever intersect.

wysota
26th September 2008, 10:26
Check the boundingRect() for both items. For instance using QRectF::intersects(). Just remember to map those rects to scene coordinates first. It's the bounding rects that may intersect, not the shapes themselves.

QbelcorT
27th September 2008, 13:11
thanks for the tips. I have done a little more debugging and noticed that when the button is pressed I have a function that scales the button from a timeline slot, the value is updated calling setTransform(QTransform().translate(x(),y()).scale (1 - value / 3.0, 1 - value / 3.0).translate(-x(),-y()));
If I take out the scaling transformation the button selection still works, and the painting is only restricted to inside the selected button, the polygon is not updated. So the cause of this painting update is when I use the transform on the object.
Does this tell you anything?
Thanks.

wysota
28th September 2008, 21:40
What do you set the transformation on?

QbelcorT
29th September 2008, 00:48
ahhhhh yes I solved the problem! :)
In the viewing class where I setup the view using QGraphicsView I set setViewportUpdateMode(MinimalViewportUpdate). The previous setting was (FullViewportUpdate). Thanks for your help.