During this summer of pre-4.2 testing, we got many feature requests from you all, customers and Open Source'rs, and I'd like to pull out one of the things we decided to implement as a result of this. Item obscurity: being able to determine whether an item is obscured, or not.
The idea is that any item can report which parts of its drawable area are completely opaque, and also whether their own bounding rect is obscured by another item. It's pretty neat! And here's how to do it. First, reimplement QGraphicsItem::opaqueArea():
QPainterPath OpaqueEllipseItem::opaqueArea() const
// returns the opaque area in local coordinates. in this
// case, the entire ellipse item is opaque.
Now, if you've got some item that's very expensive to draw, you can check a simple precondition from inside paint():
QGraphicsItem::isObscured() checks to see if your item's bounding rect is completely covered by any item on top of it.
For the moment, QGraphicsView itself doesn't use this feature by default, but this certainly opens possibilities for us. For example, partial obscurity would be really cool (being able to determine if /parts/ of your item are obscured), and we could also use the opaque area to determine the item's exposed areas. Hohoho.