Probably a trick question, but I can't find the answer.
I need to know when a QGraphicsItem gets selected. There must be a method that's called.
I know QGraphicsItem::itemChange()
but it's called too often.
Is there a better method ?
thx
edit : With this
if(change == ItemSelectedChange && scene()){
cout << "haha " << i++ << endl;
}
I get two calls every selection change.
You should take value
into consideration in the QGraphicsItem::itemChange method. What you want is probably something like this:
QVariant YourItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemSelectedChange)
{
if (value == true)
{
// do stuff if selected
}
else
{
// do stuff if not selected
}
}
return QGraphicsItem::itemChange(change, value);
}
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