code: def focusOutEvent(self, event):
          
          event.ignore()
          # Inspired from CompletionWidget.focusOutEvent() in file
          # widgets/sourcecode/base.py line 212
          if sys.platform == "darwin":
              if event.reason() != Qt.ActiveWindowFocusReason:
                  self.close()
          else:
              self.close()
docs: Reimplement Qt method to close the widget when loosing focus.