I have an application with a painting area (QGraphicsView). The user can add a graphics object to the area by clicking on it.

If the application window is inactive, the user can click on the main window to activate it. Just in this case, I'd like to ignore the MouseButtonPress event in QGraphicsView, so that no object will be added. So the desired behaviour is:

  • Click on painting area of inactive window: Activate window
  • Click on painting area of active window: Add graphics object


Using an event filter, I got the following order of events when clicking on an inactive window:

  • ApplicationActivated @ app
  • WindowActivate @ all widgets
  • MouseButtonPress @ QGraphicsView
  • MouseButtonRelease @ QGraphicsView


My first idea was to ignore the first MouseButtonPress event after a WindowActivated event. But this will also ignore the first click when the windows has been activated using the keyboard (e.g. Alt-Tab on Windows).

Any suggestions are welcome.