Results 1 to 2 of 2

Thread: [Qt] QMenu problem with method popup.

  1. #1
    Join Date
    Dec 2009
    Posts
    23
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [Qt] QMenu problem with method popup.

    Hello.

    I want to create popup menu on QListWidgets, so I create this:

    Qt Code:
    1. listWidgets->setContextMenuPolicy(Qt::CustomContextMenu);
    2. connect(listWidgets, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(popupMenu(QPoint)));
    To copy to clipboard, switch view to plain text mode 

    and slot popupMenu:

    Qt Code:
    1. void MainWindow::popupMenu(QPoint point) {
    2.  
    3. QMenu *popupMenu = new QMenu();
    4.  
    5. popupMenu->addAction("blabla");
    6.  
    7. popupMenu->popup(point);
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    All is ok because menu has been shown when I click right mouse button but not there where it should, it shows outside window application.

    How can I fix it? How to create popup menu where I click?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: [Qt] QMenu problem with method popup.

    First, pass a parent to your menu or delete it afterwards. If not, you will produces memory leaks.

    It is outside because you have to map the point. It is in local coordinates of listWidgets.

    EDIT: Or simple use QCursor::pos().

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

    Xandareva (26th July 2010)

Similar Threads

  1. Replies: 0
    Last Post: 27th April 2010, 15:15
  2. Replies: 3
    Last Post: 17th May 2009, 20:17
  3. QMenu popup: how close when clicked outside
    By powermax in forum Qt Programming
    Replies: 5
    Last Post: 4th March 2009, 03:18
  4. problem in QMenu
    By wagmare in forum Qt Programming
    Replies: 0
    Last Post: 29th January 2009, 08:56
  5. how to popup and close a QMenu
    By Placido Currò in forum Qt Programming
    Replies: 15
    Last Post: 14th May 2007, 16:41

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
  •  
Qt is a trademark of The Qt Company.