How to prevent QWidget::keyReleaseEvent from being called when a QAction's shortcut is typed

StackOverflow https://stackoverflow.com/questions/14771430

  •  07-03-2022
  •  | 
  •  

Question

In my QMainWindow subclass, I have several QActions with QKeySequence shortcuts. I have also reimplemented QWidget::keyPressEvent and QWidget::keyReleaseEvent in the main window.

If I type one of the shortcuts on my keyboard (e.g., Ctrl + C), keyPressEvent is not called in my main window, which makes sense because the relevant action wants that event instead. However, keyReleaseEvent is called for some reason. Is there any way to prevent that, or at least easily detect in keyReleaseEvent if the event matches one of the main window's shortcuts, so that I can ignore the event?

Was it helpful?

Solution

This seems to be a bug. I filed a report here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top