Results 1 to 2 of 2

Thread: Context Menu not working

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Context Menu not working

    Right click on the view, nothing happens, here's the code:

    Qt Code:
    1. view = new QTableView();
    2. connect(view, SIGNAL(customContextMenuRequested ( const QPoint &)), this, SLOT(viewMenu(const QPoint &)));
    3.  
    4. void MainWindow::viewMenu(const QPoint & pos)
    5. {
    6. QMenu *viewMenu = new QMenu("Edit Log", this);
    7. viewMenu->setContextMenuPolicy(Qt::CustomContextMenu);
    8. viewMenu->addAction("Edit");
    9. viewMenu->popup(pos);
    10. }
    To copy to clipboard, switch view to plain text mode 

    viewMenu is declared as a slot.

    so, what have I done wrong?

  2. #2
    Join Date
    Oct 2009
    Posts
    22
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Context Menu not working

    setContextMenuPolicy(Qt::CustomContextMenu);
    This function must be called before emitting signal (customContextMenuRequested).
    eg:
    view = new QTableView();
    view->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(view, SIGNAL(customContextMenuRequested ( const QPoint &)), this, SLOT(viewMenu(const QPoint &)));
    and the pos must be translated form widget coordinates to screen coordinates.more information in Qt document,Please look for
    customContextMenuRequested
    .

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

    waynew (10th January 2010)

Similar Threads

  1. Context menu
    By dejvis in forum Newbie
    Replies: 2
    Last Post: 20th September 2009, 22:02
  2. Shortcut key for context menu
    By darshan.hardas in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 20:32
  3. Qwt and context menu
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 9th December 2008, 08:55
  4. QItemDelegate Context Menu
    By aekilic in forum Qt Programming
    Replies: 16
    Last Post: 3rd December 2008, 09:29
  5. Context Menu
    By RY in forum Newbie
    Replies: 1
    Last Post: 10th September 2008, 07:59

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.