Shortcut of QAction in contextMenu has no response
Unsolved
General and Desktop
-
connect(ui->listWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenu(QPoint))); void MainWindow::customContextMenu(const QPoint &pos) QAction *action_rename; QList<QAction *> actions; ...... action_rename = new QAction(this); action_rename->setText("重命名"); action_rename->setShortcut(QKeySequence(Qt::Key_M)); actions.append(action_rename); ...... foreach(QAction *action, actions){ action->setShortcutVisibleInContextMenu(true); } QAction *result_action = QMenu::exec(actions, ui->listWidget->mapToGlobal(pos)); ...... if (result_action == action_rename) { ...... } }