c++qtqgraphicsitem

How to disable the multiple selection of qgraphicsitem?


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?


Solution

  • 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:

    You might need to block signals during modifying the selection inside the slot.