O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Item selection

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.

Another useful drag ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required