[SOLVED] QAction: get way of activation from code
AFAIN, signal can be activated with three ways:
- Click on it in QMainMenu
I have this code:
I really don’t get that requirement. What do you mean by that exactly? What is “storing QAction in application menu”? Do you mean you want to show a menu item for your action? If so, why only execute it via a shortcut? That seems strange… And if the shortcut needs to be different than the menu click, why does it need to be the same QAction?
Hmmm… It is starting to make some kind of sense to me. Let me try to re-word the requirement, so you can tell me if I understand you correctly.
You need to have an action A in a menu. When A is triggered by clicking on it, something cool happens. However, this item in the menu also needs to display a shortcut, say CTRL+A. However, due to the nature of the application, when this shortcut is used, the actual action being performed depends on the context of where the shortcut was triggered from. So, the action is actually slightly different when the menu or the shortcut triggers it. For discoverabilty of the shortcut, it is still important to advertise the shortcut for the action in the menu.
The problem tucnak then faces, is that if you actualy put the shortcut on the QAction, the QAction is triggered when the shortcut is pressed, while the subtely different version should be triggered instead. There is no way to figure out if a mouse press or a keyboard shortcut triggered the action in the first place, so you cannot filter on that in the slot connected to the QAction::triggered() signal.
Do I get that right?
If so, the option that comes to mind is to install an application wide event filter, and listen for the key shortcut key combination that way. You can filter out the event before it reaches the code that triggers the QAction to be fired.