What method is called when a QGraphicsItem get selected
qgraphicsitem, qt
Solution
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);
}
Problem
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.