[Interest] Capture keyPressEvent on QMenuBar/QMenu?

Israel Brewster ibrewster at flyravn.com
Thu Oct 11 18:36:41 CEST 2018



On Oct 11, 2018, at 2:54 AM, Frederik Christiani via Interest <interest at qt-project.org<mailto:interest at qt-project.org>> wrote:

On 11-10-2018 02:02, Tony Rietwyk wrote:
Hi Israel,
Try installEventFilter on the menu to see the KeyPress events before they are handled by the menu.

In the eventFilter you'll want to look at the events of type
QEvent::ShortcutOverride. Remember to accept() the event if you don't want the shortcut action triggered.



Ok, I tried with using an eventFilter, as per the documentation at http://doc.qt.io/qt-5/qobject.html#installEventFilter. As a test, I used their example code exactly for the implementation of the KeyPressEater class. I tried this in two ways: 1) installing the event filter on my QMenuBar object, and 2) installing the eventFilter on the base QApplication object, as per the documentation at http://doc.qt.io/qt-5/eventsandfilters.html#event-filters, which says:

"It is also possible to filter all events for the entire application, by installing an event filter on the QApplication or QCoreApplication object. Such global event filters are called before the object-specific filters."

When installed on my QMenuBar object, the eventFilter function was *never* called, as far as I can determine. When installed on the QApplication object, the eventFilter function *was* called as expected - right up until I activated a menu. ANY menu - even the Apple menu. At that point, the eventFilter function stopped receiving events.

I am running Qt 5.9.6 on MacOS X 10.13 and 10.14 (tried both with the same behavior). It sort of appears that the system is taking over the menu bar entirely, such that events simply don't make it to my application *at all* when the menu is activated. Is something like that a possibility?

-----------------------------------------------
Israel Brewster
Systems Analyst II
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7293
-----------------------------------------------
Kind regards,
Frederik

--
Frederik Christiani
Viking Software
https://www.vikingsoftware.com/
_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181011/3bc610cb/attachment.html>


More information about the Interest mailing list