PDA

View Full Version : QGraphicsScene artifacts



psih128
15th February 2011, 00:55
I have a weird problem with graphics scene. I have a somewhat complicated scene composed of several custom QGraphicsItem derived objects. The items are nested into a tree with 3 levels. One of the items derives from QGraphicsTextItem. When its parent is being dragged over the scene, the text item leaves artifacts as shown on the attachment. When the same text item is moved to a simpler test case and its parent is being dragged, it does not leave the artifacts anymore.

the implementation of the text item does not affect any of the boundingRect, shape, paint functions. I suspect that the problem is in one of the parent items. What might be the problem? How can the parent item affect the drawing of the child item?

5949

SixDegrees
15th February 2011, 01:44
It certainly looks like a BoundingRect-related problem. Try making the BR quite large, just to see if the problem goes away or diminishes.

psih128
15th February 2011, 09:01
should the bounding rect of the parent item include the bounding rects of the children items? What about the shape?

totem
15th February 2011, 10:41
Yes it should. Shapes too if you can.
What I usually do to debug is to draw the boudingRect() or shape() in the ::paint() method of the item, it's useful to see what's hapenning

MarekR22
15th February 2011, 12:52
Yes it should. Shapes too if you can.
No true. bounding rect should contain whole area where current item is painted.
This artifact can be rusult of:
- to small boundingRect
- painter not restored to initial state in paint method

totem
15th February 2011, 13:43
No true. bounding rect should contain whole area where current item is painted.

"whole area where current item is painted" = "Current item bounding rect" + "children items bounding rects"

no ?

psih128
15th February 2011, 14:24
This artifact can be rusult of:
- to small boundingRect
- painter not restored to initial state in paint method
I always thought that the painter doesn't need to be restored in paint method, unless the view has the QGraphicsView::DontSavePainterState. I dont have this flag set. In fact, that text item that hold the string "Line" is drawn by the standard implementation of QGraphicsTextItem

All the bounding rects of my items are properly calculated, and I always call painter->setClipRect(boundingRect()) to avoid any painting outside of the painter area. What else might cause the problem?

From the image I attached it looks like the scene does not erase the spots that were covered by the item before the move. Do I need to call QGraphicsItem::prepareGeometryChange, or something like this before calling QGraphicsItem::setPos?

MarekR22
17th February 2011, 14:19
QGraphicsItem::prepareGeometryChange should be called only when boundingRect is changing (on resize events for example).
Instead cheat chat what can be wrong in the code, maybe you will show code with problematic graphics item (it doesn't look to be complicated).

The fact that QGraphicsTextItem is not properly refresh doesn't mean that problem is with that item. This can be result of problems with other item.