Results 1 to 3 of 3

Thread: [SOLVED] Help Request - Table with Right-Click Context Menu

  1. #1
    Join Date
    May 2011
    Posts
    14
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question [SOLVED] Help Request - Table with Right-Click Context Menu

    Good Day Everyone,

    I have been using QT Designer (3.3.6) for about 2 weeks now and while I understand the basic concepts it seems I need help with some of the not so obvious things.

    In this caseI have a QTable in my main form. What I am looking to do is add a Right-Click context menu on the table, that has a select set of options (i.e. Delete, Add, Modify). Upon clicking on one of the options it would call a method (or I suppose the proper terminolgy is Slot) that I have written. I currently have the method set up on a button so when the user clicks it, everything works. Now I'm just looking to add the Context Menu for quicker access.

    In the research I have done I keep running across this QPopupMenu option, but not sure how to use that just yet. I have also searched the forums and did not see anything that really explains whats going on.

    Any and all help would be appreciated, even if it is a "Hey check out this post <insert link here>."

    Thanks,

    Sarol
    Last edited by Sarol; 3rd May 2011 at 22:21.

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Help Request - Table with Right-Click Context Menu

    In your widget form change the property "contestMenuPolicy" (in your right pane) to DefaultContextMenu. Right click the widget and choose "Go to Slot" -> "CustomContextMenuRequest" . It will create a function for you. Now in that function add a QMenu:

    Qt Code:
    1. void someWidget::someWidgetContextMenu(QPoint pos)
    2. {
    3. QMenu menu;
    4. menu.addAction(someActionCreatedByYou1);
    5. menu.addAction(someActionCreatedByYou2);
    6. menu.exec(QCursor::pos());
    7. }
    To copy to clipboard, switch view to plain text mode 

    Voilá. You will have to add proper includes i.e #include<QMenu>
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

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

    Sarol (9th May 2011)

  4. #3
    Join Date
    May 2011
    Posts
    14
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Help Request - Table with Right-Click Context Menu

    Greetings john_god,

    Thank you for the response. While I did not have the contestMenuPoliy option you mentioned, I was able to see where I was going wrong in setting up my menu, based off the code snippet you posted.

    I greatly appreciate your help in this matter.

    Sarol
    Last edited by Sarol; 3rd May 2011 at 22:02. Reason: spelling corrections

Similar Threads

  1. how to make the popup context menu disappear when click the options softkey ?
    By kongkong163 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 18th January 2011, 04:39
  2. context menu for table
    By sattu in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2011, 10:09
  3. Open a pop up menu when right click on any cell of the table
    By katta_ashish in forum Qt Programming
    Replies: 4
    Last Post: 9th September 2010, 08:06
  4. cancle right click context menu in qtwebkit
    By umen in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2009, 22:06
  5. QWT right click window.. (Context Menu)
    By maveric in forum Qt Programming
    Replies: 4
    Last Post: 25th May 2008, 09:07

Tags for this Thread

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.