I have made a class Hotkeys that intercepts global hotkeys.

It works great, but now when I click the menubar in the main window, the menu doesn't open.

Qt Code:
  1. Window::Window(QWidget* parent, Qt::WindowFlags flags): QMainWindow(parent, flags)
  2. {
  3. // ...
  4. Hotkeys* hotkeys = new Hotkeys(this);
  5. hotkeys->addHotkey(actionPlayPause, MOD_CONTROL, 'P');
  6. }
To copy to clipboard, switch view to plain text mode 

I'm very sure it is the hotkeys that cause this effect because if I comment that code out, the menu works again...

I thought it was something with the return values of winEvent, but those are correct according to the definition:
In your reimplementation of this function, if you want to stop the event being handled by Qt, return true and set result to the value that the window procedure should return. If you return false, this native event is passed back to Qt, which translates the event into a Qt event and sends it to the widget.
Source code of the hotkeys
hotkeys.cpp
Qt Code:
  1. #include "hotkeys.h"
  2.  
  3. void Hotkeys::addHotkey(QAction* action, UINT mod, UINT vk)
  4. {
  5. hotkeys.push_back(action);
  6. RegisterHotKey(winId(), hotkeys.size(), mod, vk);
  7. }
  8.  
  9. bool Hotkeys::winEvent(MSG* message, long* result)
  10. {
  11. if(message->message == WM_HOTKEY)
  12. {
  13. printf("WM_HOTKEY with wParam == %d\n", message->wParam);
  14. QAction* action = hotkeys.at(message->wParam-1);
  15. if(action)
  16. {
  17. action->trigger();
  18. return true;
  19. }
  20. }
  21. return false;
  22. }
To copy to clipboard, switch view to plain text mode 

hotkeys.h
Qt Code:
  1. #ifndef HOTKEYS
  2. #define HOTKEYS
  3.  
  4. #include <QWidget>
  5. #include <QAction>
  6. #include <qt_windows.h>
  7.  
  8. class Hotkeys: public QWidget
  9. {
  10. Q_OBJECT
  11. public:
  12. Hotkeys(QWidget* parent): QWidget(parent) {};
  13. void addHotkey(QAction*, UINT, UINT);
  14. private:
  15. QList<QAction*> hotkeys;
  16. bool winEvent(MSG* message, long* result);
  17. };
  18.  
  19. #endif
To copy to clipboard, switch view to plain text mode