Results 1 to 2 of 2

Thread: Right Click pop up menu .Not Working

  1. #1
    Join Date
    Jun 2013
    Qt products
    Qt4 Qt5 Qt/Embedded

    Default Re: Right Click pop up menu .Not Working

    Good Day,

    Created a signal in a subclass(qlabel)
    connected it to slot in mainWindow class(main)

    This is my code:
    Qt Code:
    1. signals:
    2. void popUpMenu();
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void qlabel::mousePressEvent(QMouseEvent *ev)
    2. {
    3. if(ev->button()==Qt::RightButton)
    4. {
    5. emit popUpMenu();
    6. }
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. connect(ui->label2, SIGNAL(popUpMenu()), this, SLOT(slPopUpMenu()));
    2. ...
    3. void MainWindow::slPopUpMenu()
    4. {
    5. QMenu *newMenu = new QMenu(this);
    6. newMenu->addAction(new QAction("do this", this));
    7. newMenu->addAction(new QAction("do that", this));
    8. newMenu->addAction(new QAction("Cancel", this));
    9. newMenu->exec(newMenu, QCursor::pos());
    10. }
    To copy to clipboard, switch view to plain text mode 

    receiving multiple errors with this code!
    Where am I going wrong?


    Added after 9 minutes:

    Not to worry... Solved
    Should have been patient before posting problem -> myBad

    Solution was in main.cpp
    Qt Code:
    1. newMenu->exec(QCursor::pos());
    To copy to clipboard, switch view to plain text mode 

    Kind Regards

    New Prob:
    Any ideas/threads out there on how to perform a function once user clicks an action on the pop up menu

    Last edited by ebsaith; 18th June 2013 at 08:38.

  2. #2
    Join Date
    Jan 2006
    Graz, Austria
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Unix/X11 Windows

    Default Re: Right Click pop up menu .Not Working

    You could also look at signal contextMenuRequested() declared in QWidget

    Or you add the actions to the label and set the label's context menu policy to ActionsContextMenu

    Last edited by anda_skoa; 18th June 2013 at 09:22.

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

    ebsaith (18th June 2013)

Similar Threads

  1. Connecting menu click with action
    By thefatladysingsopera in forum Newbie
    Replies: 1
    Last Post: 23rd August 2011, 13:52
  2. Right-click menu position
    By thuswa in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2009, 22:00
  3. QTableWidget right click menu
    By stefan in forum Newbie
    Replies: 5
    Last Post: 23rd June 2008, 19:42
  4. Right click menu
    By ^NyAw^ in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:22
  5. menu on right click on canvas
    By quickNitin in forum Newbie
    Replies: 4
    Last Post: 8th October 2006, 12:09

Tags for this Thread


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.