문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top