PDA

View Full Version : Right Click pop up menu .Not Working



ebsaith
18th June 2013, 09:38
Good Day,

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

This is my code:
qlabel.h


signals:
void popUpMenu();

qlabel.cpp


void qlabel::mousePressEvent(QMouseEvent *ev)
{
if(ev->button()==Qt::RightButton)
{
emit popUpMenu();
}
...
}

main.cpp



connect(ui->label2, SIGNAL(popUpMenu()), this, SLOT(slPopUpMenu()));
...
void MainWindow::slPopUpMenu()
{
QMenu *newMenu = new QMenu(this);
newMenu->addAction(new QAction("do this", this));
newMenu->addAction(new QAction("do that", this));
newMenu->addAction(new QAction("Cancel", this));
newMenu->exec(newMenu, QCursor::pos());
}


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

thanks

Added after 9 minutes:

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

Solution was in main.cpp


newMenu->exec(QCursor::pos());


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


Thanks

anda_skoa
18th June 2013, 10:22
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

Cheers,
_