Solved Shortcut to QAction not being triggered
-
I've defined a QAction (it's a member variable) like this:
m_p_delete_template_action = new QAction(tr("Delete")); m_p_delete_template_action->setShortcut(QKeySequence(QKeySequence::Delete)); connect( m_p_delete_template_action, &QAction::triggered, this, &SessionTemplateEditor::slotDeleteTemplate, Qt::UniqueConnection );
Then I've added the QAction to a context menu:
m_p_context_menu = new QMenu(this); m_p_context_menu->addAction(m_p_export_template_action); m_p_context_menu->addSeparator(); m_p_context_menu->addAction(m_p_delete_template_action); m_p_context_menu->addAction(m_p_export_template_action); m_p_context_menu->addSeparator(); m_p_context_menu->addAction(m_p_delete_template_action);
The context menu's parent widget is a QTableView (if that even matters). For some reason, the shortcut does not trigger at all. I don't manually handle keyboard focus anywhere.
Any ideas?
-
Ah, you know what.
Of course, it doesn't work. I added the QAction to the context menu, which isn't receiving my keyboard input. I have to add it to the QTableView as well.
Sometimes it helps to just talk about an issue. -
@qwasder85 said in Shortcut to QAction not being triggered:
m_p_context_menu->addAction(m_p_delete_template_action); m_p_context_menu = new QMenu(this);
Why do you create here a new instance?
-
@jsulm Mistake when pasting the code here. :)
-
@qwasder85 Do other shortcuts you add work?
-
@jsulm Hm, no.
-
Ah, you know what.
Of course, it doesn't work. I added the QAction to the context menu, which isn't receiving my keyboard input. I have to add it to the QTableView as well.
Sometimes it helps to just talk about an issue. -
@qwasder85 said in Shortcut to QAction not being triggered:
Ah, you know what.
Of course, it doesn't work. I added the QAction to the context menu, which isn't receiving my keyboard input. I have to add it to the QTableView as well.
Sometimes it helps to just talk about an issue.It's called
Rubber Duck Debugging
Don't forget to set the topic to solved :)