Hi folks,
When I create my own GraphicsItems (or -Objects or -Widgets), the two main approaches would either be composition (i.e. I add sub-items and let my custom item act like a "Group of items"), or custom painting (i.e. I write my own paint routine, bounding rectangle and shape implementations).
Both have their advantages - of course, pure composition is much easier, as I do not have to worry about things like the BoundingRect or Shape, individual items within my "group" can be selected, and collision detection works.
Custom painting is much more powerful, and (if done right) can yield better performance (e.g. I do not clutter the Bsp tree with objects that do not need to be selected or moved around individually). I have much more control on what is done, and how much is done.
In some cases, mixing those two approaches sounds attractive: Custom paint those parts of a GraphicsItem that would be complex to compose, and that need not worry about things like selection or collision detection.
Compose those parts out of other GraphicsItems that require things like selection or collision detection.
What would I have to watch out for?
I assume one limitation is that the custom painting can only occur either as background or as foreground, since I need to call the QGraphicsItem::paint routine at some point, and it will paint all my "grouped" items according to z-order, in one go. I can either put my custom painting code before or after that (or both), but not in-between items.
What would I do about the boundingRect and shape methods? How would I include the boundingRect and shape info of my composite items into my own, custom paint boundingRect and shape info?
Any other pitfalls you see in that concept?
Edit: Removed unintentional smily
Bookmarks