0

Very simple Qt GUI application:

  • On the scene I have multiple circles implemented as QGraphicsItem
  • boundingRect returns square around this circle.
  • Method 'shape' is not overridden.

The problem appears when in paint() method I've added:

if (isSelected()) {
    painter->drawRect(re);
}

Selection is drawn well, but unselection doesn't cause redrawing. At log level I can see that item really lost selection flag. Calling update() from itemChange is useless also. Thank you in advance for any suggestion.

Dewfy
  • 23,277
  • 13
  • 73
  • 121

2 Answers2

0

After 10 days I returned back to this problem and discovered that my QGraphicsItem constructed with setCacheMode(DeviceCoordinateCache); OMG! Stupid mistake, when this line was removed (by default QGraphicsItem::NoCache used) selection is redrawn well.

Dewfy
  • 23,277
  • 13
  • 73
  • 121
  • can u explain me why this flag setCacheMode is creating the problem ..right now im facing the same problem. if i set the QGraphicsProxyWidget with this flag its not showing the label properly untill i set the viewport to opengl. – Wagmare Sep 30 '13 at 10:04
  • 1
    @Wagmare it is rather simple - because border around item is not appeared in cache. Cache of DeviceCoordinateCache level is too good that is why changes of border is not appeared in it. – Dewfy Sep 30 '13 at 18:45
  • thx for much useful reply.. so how i can use cache on QGraphicsProxyWidget as i need to add more than thousand items its required to use cache.? – Wagmare Oct 01 '13 at 03:59
  • borders are visible but only the pixmap is not visible..some times partially visible i some areas .. – Wagmare Oct 01 '13 at 05:22
  • @Wagmare try to change CacheMode level (see at http://qt-project.org/doc/qt-5.0/qtwidgets/qgraphicsitem.html#CacheMode-enum) or totally remove `setCacheMode` – Dewfy Oct 01 '13 at 06:05
0

You can also try to change the default QGraphicsView::MinimalViewportUpdate to FullViewportUpdate with setViewportUpdateMode(QGraphicsView::FullViewportUpdate);

Or you can call scene()->update(); from the item to schedule a repaint.

One of them was required at least when I kept changing the QGraphicsItem::ItemHasNoContents flag on an item.

kleimola
  • 113
  • 6