code: def restore_expanded_state(self):
          
          if self.__expanded_state is not None:
              # In the old project explorer, the expanded state was a dictionnary:
              if isinstance(self.__expanded_state, list):
                  self.fsmodel.directoryLoaded.connect(
                                                    self.restore_directory_state)
                  self.fsmodel.directoryLoaded.connect(
                                                  self.follow_directories_loaded)
docs: Restore all items expanded state