I have a context menu (QMenu) and add a copy action to it like this:
m_copyNodeAction = new QAction(tr("Copy node"), &m_mainContextMenu);
m_copyNodeAction->setShortcut(QKeySequence("Ctrl+C"));
m_copyNodeAction->setShortcutVisibleInContextMenu(true);
m_mainContextMenu.addAction(m_copyNodeAction);
QObject::connect(m_copyNodeAction, &QAction::triggered, [this] () {
std::cout << "Copy node triggered!" << std::endl;
});
The menu is opened like this (the hosting class is derived from a QGraphicsView
):
m_mainContextMenu.exec(mapToGlobal(m_clickedPos));
The menu shows the action OK, but it doesn't trigger by Ctrl+C
. I have used the same approach for actions in my main menu so why is this different?
I have also tried to set some other shortcuts, but nothing works.