PDA

View Full Version : How to place contextmenu in QGraphicsScene?



Morea
14th January 2007, 15:43
void Fraga::contextMenuEvent(QGraphicsSceneContextMenuE vent* e)
{
QMenu menu;
QPoint p= (mapToParent(e->scenePos())).toPoint();
menu.addAction(_nyttsvar);
menu.exec( p );
}

Fraga is an QGraphicsRectItem. This is the code, but it doesn't seem to get maped to the correct coordinatesystem. A call to the above function places the menu outside of the Mainwindow, which is not exactly what I had hoped for.
The menu should be placed close to the mouse cursor, of course. But I don't know how.

jpn
14th January 2007, 15:56
[CODE]The menu should be placed close to the mouse cursor, of course. But I don't know how.
QGraphicsSceneContextMenuEvent::screenPos()


Returns the position of the mouse cursor in screen coordinates at the moment the the context menu was requested.



menu.exec( e->screenPos() );

Morea
14th January 2007, 16:04
Thank you very much jpn, you have helped me a lot today! :)