开发者

QGraphicsItem unselect redraw problem

开发者 https://www.devze.com 2022-12-08 17:41 出处:网络
Very simple Qt GUI application: On the scene I have multiple ci开发者_如何学运维rcles implemented as QGraphicsItem

Very simple Qt GUI application:

  • On the scene I have multiple ci开发者_如何学运维rcles 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号