Problem with QAction's shortcut and QMenu
When i add an action to a QMenu, wich is added to QMenuBar() in QMainWindow, the QAction's shortcut works fine. But, when i do:
the shortcut doesn't answer anymore, any idea?
If you hide the menu, the action is also hidden if it is not used on any other object.
Am I right, that it is not connected additionally to a toolbar?
You are right Gerolf, the actions added to the toolbar still answering to the shortcut. What do you suggest to fix that?
If an action is completely hidden, it is disabled. If you need global shortcuts, event when the actions UI stuff is hidden, us "QShortcut":http://doc.qt.nokia.com/4.7/qshortcut.html
shortcut = new QShortcut(QKeySequence(tr("Ctrl+O", "File|Open")), this);
connect(shortcut, SIGNAL(activated ()), this, SLOT(fileOpen()));
yeah, that works, and i've done something like that, but then if the menu is visible (hiding and showing is done by the user) i get to another problem:
@QAction::eventFilter: Ambiguous shortcut overload: Ctrl+O@
and the only thing comes to my mind is to implement something that manage the shortcuts according to the menu state, what's your opinion about that?
you could remove the shortcut from the action, as it is available by the shortcut instance :-)
yes, i can do that too, but it's going to be a pain in the a** since i need to consider wich action is in the toolbar (also configurable in the ui) :-P
anyway, thanks you for answering so fast.
I found out that setting the height to 0 might do the job. The menu is gone, but the shortcuts are still working (tested under Qt 5.4.2).