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

Finding items by position

If you want to know which item is shown at a certain position, you can use the QGraphicsScene::itemAt() function that takes the position in the scene's coordinate system (either a QPointF or two qreal numbers) and the device transformation object (QTransform) that can be obtained using the QGraphicsView::transform() function. The function returns the topmost item at the specified position or a null pointer if no item was found. The device transformation only matters if your scene contains items that ignore transformations. If you have no such items, you can use the default-constructed QTransform value:

QGraphicsItem *foundItem = scene.itemAt(scenePos, QTransform());

If your scene contains items that ignore transformations, ...

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