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 set setViewportUpdateMode(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.


  • Moderators

    @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.


  • Moderators

    @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.


Log in to reply
 

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