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();
signals:
void popUpMenu();
To copy to clipboard, switch view to plain text mode
qlabel.cpp
{
if(ev->button()==Qt::RightButton)
{
emit popUpMenu();
}
...
}
void qlabel::mousePressEvent(QMouseEvent *ev)
{
if(ev->button()==Qt::RightButton)
{
emit popUpMenu();
}
...
}
To copy to clipboard, switch view to plain text mode
main.cpp
connect(ui->label2, SIGNAL(popUpMenu()), this, SLOT(slPopUpMenu()));
...
void MainWindow::slPopUpMenu()
{
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());
}
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());
}
To copy to clipboard, switch view to plain text mode
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());
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
Thanks
Bookmarks