It seems the default for multiple selection of QGraphicsItem
is to press Ctrl button.
But is it possible to disable this function? Or reload this function?
This is controlled by the items' flags. To disable selection for a particular item, do
item->setFlag(QGraphicsItem::ItemIsSelectable, false);
If you want to completly disable selecting items for a QGraphicsScene
regardless of the item flags I would recommend to connect QGraphicsScene::selectionChanged
to QGraphicsScene::clearSelection
.
If you want to disable multiple selection I suggest the following:
lastSelection
to a QGraphicsItem aroundQGraphicsScene::selectionChanged
selectedItems
:
lastSelection
: nothing to do (=selection didn't really change)lastSelection
: set lastSelection
to that item (=one item selected for the first time)lastSelection
. Remove that one from the selection (lastSelection->setSelected(false);
), set lastSelection
to the remaining item. (=another item was selected, move selection to it)You might need to block signals during modifying the selection inside the slot.