Unsolved How use QGraphicsScene::itemAt ?
-
Hi!
I have QGraphicsScene
How use QGraphicsScene::itemAt ?
What should be in place of const QTransform &deviceTransform? -
Hi,
Straight from the documentation:
deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations.
-
But how to use it? I'm drawing on a QGraphicsScene and I want this method to get the element under the mouse.
-
Are you sure you're not rather looking for the equivalent in QGraphicsView ?
-
I honestly don't care. I have a separate class inherited from QGraphicsScene. In this class I draw on QGraphicsScene. And I need to get information about the drawn object under the mouse How can this be implemented?
-
@Mikeeeeee said in How use QGraphicsScene::itemAt ?:
In this class I draw on QGraphicsScene.
...and you display the scene using a
QGraphicsView
, right?And I need to get information about the drawn object under the mouse
QGraphicsScene
does not understand mouse coordinates.QGraphicsView
transforms mouse coordinates into scene coordinates.You have two options to get the item under your mouse:
- Use
QGraphicsView::itemAt()
, OR - Call
QGraphicsView::mapToScene()
followed byQGraphicsScene::itemAt()
.
More info: https://doc.qt.io/qt-5/graphicsview.html#coordinate-mapping
- Use