PDA

View Full Version : QGraphicsView coordinate to QGraphicsScene



nilot
3rd November 2016, 13:28
Hello,

In my custom QGraphicsScene class, I display the following two values :


void MainScene::contextMenuEvent(QGraphicsSceneContextM enuEvent *event)
{
qDebug()<<views()[0]->mapToScene(event->screenPos());
qDebug()<<event->scenePos(); // not equal to the previous value
QGraphicsScene::contextMenuEvent(event);
}

I don't understand why the two values are different. How can I map event->screenPos() to scene coordinates correctly ?

Thank you

anda_skoa
3rd November 2016, 16:57
If you look at the method names, and their documentation, then you'll notice that you are trying to map a "screen pos" into the scene using a method of the view.
So unless your view has no decoration and is located at 0/0 of the screen, there will be offset.

But why do you need this in the first place, QGraphicsContextMenuEvent has a "scene pos" getter already?

Cheers,
_