Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What method is called when a QGraphicsItem get selected

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.

like image 384
Matthieu Riegler Avatar asked Apr 23 '12 19:04

Matthieu Riegler


1 Answers

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);
}
like image 97
Anthony Avatar answered Dec 24 '22 10:12

Anthony