views:

170

answers:

2

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.

A: 

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
A: 

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