code: def event(self, ev):
          
          if ev.type() == QtCore.QEvent.WindowActivate:
              logger.debug("Window activated: {}".format(self.windowNumber))
              self.activateWindowAction.setChecked(True)
  
          return super(MainWindow, self).event(ev);
docs: Detects the WindowActivate event. Pass all event through to the super class.