boo9
12th June 2016, 16:03
Right Click created menu on top of QTableView does not go away after clicking on action item.
After the right click on QTableView the menu pops up.
- 1st click on menu item (triggers signal/slot), but dont close the menu, 2nd click anywhere does close the menu.
- 1st click anywhere (outside of menu) does not close the menu, 2nd click anywhere closes the menu.
How do I force to close the menu after item triggered event ?
void myRLCstuff::on_tableView_customContextMenuRequeste d(const QPoint &pos)
{
QMenu * menu = new QMenu(this);
// connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(testMenu_actionTriggered(QAction*)));
QAction * action = new QAction("&Add Record", menu);
menu->addAction(action);
// connect(action, SIGNAL(triggered()), this, SLOT(on_action_AddRecord_triggered()));
menu->popup(ui->tableView->viewport()->mapToGlobal(pos));
}
I have been on this for hours,
- I tried connect(triggered, testMenu_actionTriggered) and issuing menu->hide/close in testMenu_actionTriggered to no avail
- I tried one shot timer delay 100ms, => (menu, close/hide) to no avail.
- I tried 'menus' example and it works there as expected, but in my app using QTableView this dont work.
- If I add "QMessageBox popup before "menu->popup" line, I need two clicks on button "OK" to dismiss the button :(
qt version 5.5.1 (qt creator 3.6)
EDIT: I realized that the custom context event was firing up two times.
In UI editor, I had contextMenuPolicy=DefaultContextMenu, and in the code I had
view->setContextMenuPolicy(Qt::CustomContextMenu);
connect(view, SIGNAL(customContextMenuRequested(QPoint)), this,
SLOT(on_tableView_customContextMenuRequested(QPoin t)));
That was causing on_tableView_customContextMenuRequested to fire twice
I fixed this by deleting above code and setting UI editor contextMenuPolicy=CustomContextMenu
I dont understand though how qt runtime connects contextMenuPolicy=CustomContextMenu setting to on_tableView_customContextMenuRequested() member ?
After the right click on QTableView the menu pops up.
- 1st click on menu item (triggers signal/slot), but dont close the menu, 2nd click anywhere does close the menu.
- 1st click anywhere (outside of menu) does not close the menu, 2nd click anywhere closes the menu.
How do I force to close the menu after item triggered event ?
void myRLCstuff::on_tableView_customContextMenuRequeste d(const QPoint &pos)
{
QMenu * menu = new QMenu(this);
// connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(testMenu_actionTriggered(QAction*)));
QAction * action = new QAction("&Add Record", menu);
menu->addAction(action);
// connect(action, SIGNAL(triggered()), this, SLOT(on_action_AddRecord_triggered()));
menu->popup(ui->tableView->viewport()->mapToGlobal(pos));
}
I have been on this for hours,
- I tried connect(triggered, testMenu_actionTriggered) and issuing menu->hide/close in testMenu_actionTriggered to no avail
- I tried one shot timer delay 100ms, => (menu, close/hide) to no avail.
- I tried 'menus' example and it works there as expected, but in my app using QTableView this dont work.
- If I add "QMessageBox popup before "menu->popup" line, I need two clicks on button "OK" to dismiss the button :(
qt version 5.5.1 (qt creator 3.6)
EDIT: I realized that the custom context event was firing up two times.
In UI editor, I had contextMenuPolicy=DefaultContextMenu, and in the code I had
view->setContextMenuPolicy(Qt::CustomContextMenu);
connect(view, SIGNAL(customContextMenuRequested(QPoint)), this,
SLOT(on_tableView_customContextMenuRequested(QPoin t)));
That was causing on_tableView_customContextMenuRequested to fire twice
I fixed this by deleting above code and setting UI editor contextMenuPolicy=CustomContextMenu
I dont understand though how qt runtime connects contextMenuPolicy=CustomContextMenu setting to on_tableView_customContextMenuRequested() member ?