How to check if action is triggered by click or shortcut

I have an action with a shortcut associated and I want to identify if my action was triggered by clicking or using the shortcut.

ChatGPT told me that I can use the event parameter passed to my function, but it is a bool instead of QActionEvent. It provided this sample code:

if isinstance(event, QActionEvent) and event.isShortcut():

My action:

curr_shortcut = app_settings.value("shortcut", defaultValue="W")
ankipa_action = QAction("AnkiPA...", mw)

You don’t get an event when connecting to a signal like in ankipa_action.triggered.connect(main_dialog). You probably need to install an event filter for that and there are many resources online that instruct you how to do that, or you ask ChatGPT if you prefer. However, I would reconsider if you really need to make that distinction.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.