The scene implements the concept of focus that works similar to keyboard focus in widgets. Only one item can have focus at a time. When the scene receives a keyboard event, it is dispatched to the focus item.
To be focusable, an item must have the QGraphicsItem::ItemIsFocusable flag enabled:
item1->setFlag(QGraphicsItem::ItemIsFocusable, true);item2->setFlag(QGraphicsItem::ItemIsFocusable, true);
Then, an item can be focused by a mouse click. You can also change the focused item from the code:
Another way to set the focus is to use the scene's QGraphicsScene::setFocusItem() function, which expects a pointer to the item you like to focus as a parameter. Every time an item gains focus, the ...