The scene supports the ability of selecting items, similar to how you select files in a file manager. To be selectable, an item must have the QGraphicsItem::ItemIsSelectable flag turned on. Try to add parent->setFlag(QGraphicsItem::ItemIsSelectable, true) to the createComplexItem() function we created earlier. Now, if you run the application and click on a rectangle, it is selected, which is indicated by dashed lines:
You can use the Ctrl button to select multiple items at once. Alternatively, you can call view.setDragMode(QGraphicsView::RubberBandDrag) to activate the rubber band selection for the view.