QGraphicsView cache problem
-
I am using QGraphicsView/QGraphicsScene to render a set of dynamic items (markers)
sample
During for about 15 seconds everything is ok. But then appears an abnormal graphics artifact - parts of markers or even the hole of them do not disappear when I call hide() method
artifact
It seems that the problem is in view's cache, cause when I call resetCachedContent() this traces disappear.
Is there a way to manipulate views's cache? Is there a way to reset cached content right after cache is overflown? -
Is it possible that the
QGraphicsItem::boundingRect()
implementation is wrong (the rect is too small)? Note that when you paint a rectangle, half the pen width is OUTSIDE of the rectangle. The bounding rect must include that.Other than that, you might want to have a look at
QGraphicsView::ViewportUpdateMode
. -
@Joel-Bodenmann no, bounding rect is big enough, I have tested expanded rect too - it doesn't fix the problem.
But the second your advice does! I have setsetViewportUpdateMode(QGraphicsView::FullViewportUpdate);
and no traces were kept on the scene. Thanks a lot!
I hope that this mode doesn't lead to much overhead and performance cost. -
@0...-5
what kind of QGraphicsItem are your items?
In case you implemented a custom item you may want to show the implementation? -
@raven-worx It is a custom item, but it's design is quite simple. It is based on a QPainterPath, which is drawn with some brush and Qt::NoPen. I don't think implementation plays a key role here.
-
@0...-5 said:
I don't think implementation plays a key role here.
I don't share this opinion.
Whats so special about your custom item, why do you need it?
To check your implementation you can try to insert QGraphicsPathItem instead. If the issues are gone it is your implementation. If not then the cause is somewhere else. -
@raven-worx I mean drawing part is quite simple, but there is a stuff QGraphicsPathItem doesn't provide, so I had to implement my own class. I will make some experiments with QGraphicsPathItem later, but for now viewportUpdateMode solves an issue.