i have a little problem
I am programming Petri Net simulator...
I have two different classes
class PNItem : public QObject, public QGraphicsItem
...
and
class PNEdge : public QGraphicsLineItem
when i call...
QGraphicsItem *QGraphicsScene::ItemAt(//cursor position)
, is it possible somehow to get to know, what item i have clicked on? resp. what item is given item by ItemAt?
GraphicsItem::type() is intended to be used 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; }
...
};
Which would then allow you to do this:
QGraphicsItem *item = scene->itemAt( x, y );
switch( item->type() )
{
case PNItem:
...
break;
}
doing this also enables the usage of qgraphicsitem_cast
See also: QGraphicsItem::UserType
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With