GraphicsItem :: type () is designed to solve this problem.
So, you would do something like this, for example:
enum ItemType { TypePNItem = QGraphicsItem::UserType + 1,
TypePNEdge = QGraphicsItem::UserType + 2 }
class PNItem : public QObject, public QGraphicsItem {
public:
int type() { return TypePNItem; }
...
};
What will allow you to do this:
QGraphicsItem *item = scene->itemAt( x, y );
switch( item->type() )
{
case PNItem:
...
break;
}
it also allows you to use qgraphicsitem_cast
See also: QGraphicsItem :: UserType
Chris source
share