Results 1 to 3 of 3

Thread: How to place contextmenu in QGraphicsScene?

  1. #1
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to place contextmenu in QGraphicsScene?

    Qt Code:
    1. void Fraga::contextMenuEvent(QGraphicsSceneContextMenuEvent* e)
    2. {
    3. QMenu menu;
    4. QPoint p= (mapToParent(e->scenePos())).toPoint();
    5. menu.addAction(_nyttsvar);
    6. menu.exec( p );
    7. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to place contextmenu in QGraphicsScene?

    Quote Originally Posted by Morea View Post
    [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.
    Qt Code:
    1. menu.exec( e->screenPos() );
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to place contextmenu in QGraphicsScene?

    Thank you very much jpn, you have helped me a lot today!

Similar Threads

  1. contextmenu with MDI
    By Thoosle in forum Qt Programming
    Replies: 1
    Last Post: 1st December 2006, 07:29
  2. QGraphicsScene segmentation fault
    By maxpower in forum Qt Programming
    Replies: 2
    Last Post: 20th November 2006, 18:28
  3. Replies: 1
    Last Post: 18th July 2006, 12:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.