Results 1 to 6 of 6

Thread: How to call contextMenuEvent on Qt::Key_F5?

  1. #1
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question How to call contextMenuEvent on Qt::Key_F5?

    How to call contextMenuEvent on Qt::Key_F5? I want to display popup menu on Qt::Key_F5.

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to call contextMenuEvent on Qt::Key_F5?

    Well,

    You don't need to call contextMenuEvent to display a context menu.

    When you catch Qt::Key_F5 in keyPressEvent(), you just have to build a QMenu, and exec it at the cursor's current position ( QCursor:os() )

    Maybe there are another ways though ;-)

  3. The following user says thank you to guilugi for this useful post:

    rajesh (12th January 2007)

  4. #3
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Red face Re: How to call contextMenuEvent on Qt::Key_F5?

    Thanks! its working.
    But..

    I have a QTreeWidget and if any tree item is selected and user pressed F5 key then popup menu should be displyed.
    problem is, if tree item is selected and mouse pointer is somewhere else then QCursor::Pos() displaying popup menu at mouse pointer position not tree item position.

    how to display popup menu at selected tree item position?

    Thanks & Regards
    Rajesh


    Quote Originally Posted by guilugi View Post
    Well,

    You don't need to call contextMenuEvent to display a context menu.

    When you catch Qt::Key_F5 in keyPressEvent(), you just have to build a QMenu, and exec it at the cursor's current position ( QCursor:os() )

    Maybe there are another ways though ;-)

  5. #4
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to call contextMenuEvent on Qt::Key_F5?

    I don't think there's a direct method to obtain position of an item...

    Maybe this would work : when you select an item by clicking, save the cursor position in a variable...and if you call context menu with the cursor away, then use the saved position (assuming you haven't selected anything else :-) )

  6. #5
    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 call contextMenuEvent on Qt::Key_F5?

    Quote Originally Posted by rajesh View Post
    how to display popup menu at selected tree item position?
    You can get the geometry of the current/selected item by QTreeWidget::visualItemRect(). Popup the menu for example at the preferred corner of the item (remember to map the coordinate to the global coordinate system, see QWidget::mapToGlobal()).
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    rajesh (30th January 2007)

  8. #6
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to call contextMenuEvent on Qt::Key_F5?

    That's the good way

Similar Threads

  1. QGraphicsView and contextMenuEvent
    By laurabee in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2006, 23:22
  2. Call on Parent Object
    By hufgardm in forum Newbie
    Replies: 1
    Last Post: 7th September 2006, 16:11
  3. why cant i call setGeometry
    By freegnu in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2006, 05:59
  4. contextMenuEvent has issues since 4.1.3
    By momesana in forum Qt Programming
    Replies: 9
    Last Post: 31st May 2006, 18:27
  5. virtual overloaded functions and base class function call...
    By nouknouk in forum General Programming
    Replies: 7
    Last Post: 11th March 2006, 22:26

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.