Solved How To Close QMenu
-
void Dialog::on_tableWidget_customContextMenuRequested(const QPoint &pos)
{myMenu = new QMenu(); QAction *editUserAction0 = myMenu->addAction("&რედაქტირება", this, SLOT(EditSLOT())); editUserAction0->setIcon(QIcon(":/SMSicons/edit.png")); editUserAction0->setEnabled(true); QAction *editUserAction1 = myMenu->addAction("&წაშლა", this, SLOT(RemoveSLOT())); editUserAction1->setIcon(QIcon(":/SMSicons/remove.png")); editUserAction1->setEnabled(true); myMenu->exec(ui->tableWidget->mapToGlobal(pos));
}
How can i do so after the slot to close off the menu?
After performing the slot, he still appears. -
Add
delete myMenu;
after themyMenu->exec();
? -
@artwaw
nothing -
@Taz742 said in How To Close QMenu:
After performing the slot, he still appears.
what do you mean? The menu stays visible?
According to the code you've posted this won't happen. -
@raven-worx said in How To Close QMenu:
what do you mean? The menu stays visible?
YES.
After clicking on the menu, I will show a dialogue.
After disconnecting the dialogue I do not want the menu to be visible anymore. -
@Taz742
please post your code from theRemoveSLOT()
andEditSLOT()
slots. -
@Taz742
in case you are creating another event loop in the slots you need to do this instead:void Dialog::on_tableWidget_customContextMenuRequested(const QPoint &pos) { myMenu = new QMenu(); QAction *editUserAction0 = myMenu->addAction("&რედაქტირება"); editUserAction0->setIcon(QIcon(":/SMSicons/edit.png")); editUserAction0->setEnabled(true); QAction *editUserAction1 = myMenu->addAction("&წაშლა",); editUserAction1->setIcon(QIcon(":/SMSicons/remove.png")); editUserAction1->setEnabled(true); QAction* action = myMenu->exec(ui->tableWidget->mapToGlobal(pos)); if( action == editUserAction0 ) this->EditSLOT() else if ( action == editUserAction1 ) this->RemoveSLOT() }
-
@raven-worx
I am Sorry.Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); ui->tableWidget->setColumnCount(3); ui->tableWidget->setColumnWidth(1, 120); ui->tableWidget->setColumnWidth(2, 300 - 120); ui->tableWidget->hideColumn(0); ui->tableWidget->setHorizontalHeaderLabels(QStringList() << "" << "სახელი" << "ტელეფონი"); ui->tableWidget->verticalHeader()->hide(); ShowContacts(); ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_tableWidget_customContextMenuRequested(QPoint))); }
I had another connection with the constructos. And he would have appeared twice of course.
-
@raven-worx said in How To Close QMenu:
QAction* action = myMenu->exec(ui->tableWidget->mapToGlobal(pos));
if( action == editUserAction0 )
this->EditSLOT()
else if ( action == editUserAction1 )
this->RemoveSLOT()
}Oh its good.
Thank you for this.