Search code examples
qtqgraphicsitemsceneunselect

QGraphicsItem unselect redraw problem


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.


Solution

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