Since most of the convenient QGraphicsScene and QGraphicsItem functions (e.g. items (), collidingItems (), childItems (), etc.) return a QList, you are forced to do a lot of qgraphicsitem_cast or static_cast and QGraphicsItem :: Type () checks to get the actual items when you have many different items in the scene. I thought many subclasses were not the desired coding style, but I think that in this case there is no other viable way or is there?
QList<QGraphicsItem *> itemsHit = someItem->collidingItems(Qt::IntersectsItemShape);
foreach (QGraphicsItem *item, itemsHit) {
if (item->type() == QGraphicsEllipseItem::type()) {
QGraphicsEllipseItem *ellipse = qgraphicsitem_cast<QGraphicsEllipseItem *>(item);
}
else if (item->type() == MyItemSubclass::type()) {
MyItemSubClass *myItem = qgraphicsitem_cast<MyItemSubClass *>(item);
}
}
The above qgraphicsitem_cast can be replaced with static_cast, since the correct type has already been checked. When you do a lot of them all the time (a very dynamic scene), will a lot of castings affect performance beyond the usual if-else evaluation?