[Interest] Capture keyPressEvent on QMenuBar/QMenu?

Israel Brewster ibrewster at flyravn.com
Wed Oct 10 22:07:20 CEST 2018

I want to modify a QAction if the user holds down a specific key. You can see similar behavior on the Mac, for example, if you pull down the Apple menu and press/release the option key - "About This Mac" changes to "System Information...", among other things. This is the behavior I want to emulate in my application.

To that end, I tried overriding the keyPressEvent on both the QMenuBar and the QMenu containing the QAction. However, my debugging indicated that neither of these keyPressEvent functions were called when pressing any key with the relevant QMenu displayed.

I'm sort of wondering if this is perhaps due to the event being handled at a lower level in order to provide "type ahead" type functionality in the menu? I did notice that different menu entries are selected when typing various keys, which I believe to be normal behavior.

Regardless, how can I respond to a keyPress type event in a QMenuBar or QMenu?

Israel Brewster

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181010/42e75cdf/attachment.html>

More information about the Interest mailing list