使用QAction快捷方式的正确方法是什么?我有带有自定义上下文菜单的QTableView,在其中我要执行其他操作Refresh F5
:
// Popup
QAction *a;
a = mPopup.addAction(IconsManager::icon(fa::refresh), "Refresh", this, &UserPlaylistsSubWidget::refreshList, QKeySequence(Qt::Key_F5));
a->setShortcutVisibleInContextMenu(true);
首先,我必须设置setShortcutVisibleInContextMenu
使其在上下文菜单中可见,但是当按F5键(QTableView处于活动状态且焦点突出的小部件)时,动作仍未触发。还为QAction::setShortcutContext
尝试了不同的值,但仍然没有结果。
Qt 5.12。 Linux(KDE Neon)
编辑:这是弹出窗口的代码
connect(ui->list, &QWidget::customContextMenuRequested, this, &UserPlaylistsSubWidget::popUp);
void UserPlaylistsSubWidget::popUp(const QPoint &pos)
{
mPopup.popup(ui->list->viewport()->mapToGlobal(pos));
}
答案 0 :(得分:0)
弄清楚了。不知道QTableView有自己的动作列表,并且可以使用Boolean
在自己的弹出窗口中显示它。因此,这里是正确的解决方案,F5快捷键可以按预期工作:
setContextMenuPolicy(Qt::ActionsContextMenu)