Qt C ++ Mapping coords在鼠标pos的场景中创建QGraphicsItem

时间:2015-08-27 23:10:50

标签: c++ qt qgraphicsview qgraphicsitem qgraphicsscene

我想在鼠标位置添加新的椭圆(可移动的自定义QGraphicsItem)。如何将coords映射到椭圆项目以获得正确的场景位置?例如,从contextMenuEvent我得到QPointF coords = event->scenePos();,我想在那里创建椭圆。我有自定义QGraphicsScene MyScene,其中我指向QGraphicsView* view

我使用event表单void MyScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)

QPointF coords = event->scenePos();

QPointF ellpiseCoords = view->mapToScene(coords.x(), coords.y())

我总是错误的转变。我应该如何从event->scenePos() mapToScene coords以获得场景中的正确坐标,我将能够在QRectF(ellpiseCoords.x(), ellpiseCoords.y(), 50, 50);上创建椭圆作为boundingRect()

0 个答案:

没有答案