code: def change_last_focused_widget(self, old, now):
          
          if (now is None and QApplication.activeWindow() is not None):
              QApplication.activeWindow().setFocus()
              self.last_focused_widget = QApplication.focusWidget()
          elif now is not None:
              self.last_focused_widget = now
  
          self.previous_focused_widget =  old
docs: To keep track of to the last focused widget