title: PyQt5 : how can I get the content of a QTextEdit to refresh on tab change?
body: <p>[Question reformulated for clarity]</p>
  <p>I have a simple GUI with 2 tabs, the first one contains a read only QTextEdit used for program logs, the second one contains various widgets for user input and a &quot;generate&quot; button.</p>
  <p>The GUI was made using Qt Designer. Note : all elements have default attributes ( they were not edited / no options changed ) apart from the QTextEdit that is read only<br/>
  The arrows are to show the QTextEdit that is used for the logs and the generate button that causes the tab change</p>
  <p><a href="https://i.stack.imgur.com/uXmks.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uXmks.png" alt="enter image description here" /></a></p>
  <p>Upon clicking on the generate button, the focused tab is switched to the first one ( with the logs ) and a separate thread is used to compute the user data and write it's log onto the QTextEdit</p>
  <pre><code>class GUI:
      def __init__(self, core):
          self.core = core
          self.app = QtWidgets.QApplication(sys.argv)
          self.window = Application()
          self.__link_buttons__()
  
      def __link_buttons__(self):
          generate_button = self.window.get_generate_button()
          if generate_button is None:
              raise RuntimeError(&quot;could not find the generation button needed for the gui ( possibly an issue with the .gui file ), cannot start software&quot;)
          generate_button.clicked.connect(self.__generate_threaded)
  
      def __generate_threaded(self):
          logger.logger_instance.log(&quot;user requested generation&quot;, LogLevel.NORMAL)
          self.window.set_main_tab_to_log()
          if self.core.check_if_generating() is True:
          logger.logger_instance.log(&quot;Generator is currently in use&quot;, LogLevel.ERROR)
              return
          thread = threading.Thread(target=self.core.generate_gui)
          thread.start()
  
  class Application(QtWidgets.QMainWindow):
      def __init__(self):
          super(Application, self).__init__()
          self.ui = uic.loadUi(settings.settings_instance.gui_path / &quot;main_window.ui&quot;, self)
          self.show()
          self.__tabs = self.ui.findChild(QTabWidget, &quot;mainTabs&quot;)
          self.__log_tab = self.ui.findChild(QWidget, &quot;logTab&quot;)
  
      def get_gui_handle(self):
          return self.ui.findChild(QTextEdit, &quot;LogOutput&quot;)
  
      def get_generate_button(self):
          return self.ui.findChild(QPushButton, &quot;generateButton&quot;)
  
      def set_main_tab_to_log(self):
          self.__tabs.setCurrentWidget(self.__log_tab)
  </code></pre>
  <p>The logger is the class that is in charge of writing to the QTextEdit on the GUI, it calls the <code>get_gui_handle()</code> method on start to get the QTextEdit and then uses <code>append()</code> to write to it ( with thread protection )</p>
  <p>Possibly important details : I am using the standard Python threads ( <code>import threading</code> ), not the Qt as the rest of the software uses them and I am unsure if they can be mixed</p>
  <p>The logger does write successfully to the QTextEdit but the application does not display the text as intended. Any new text is displayed normally but the previous logs are not and will only show upon window resize / clicking on the text / changing tabs / ... ( what I presume are events that get the application to re-render the QTextEdit )</p>
  <p>Pictures for clarity :</p>
  <p>First log is displayed as intended :</p>
  <p><a href="https://i.stack.imgur.com/zhllc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zhllc.png" alt="enter image description here" /></a></p>
  <p>Second log is also displayed as intended but the first log is now invisible</p>
  <p><a href="https://i.stack.imgur.com/9sp7N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9sp7N.png" alt="enter image description here" /></a></p>
  <p>First log is displayed again after window resize / text overlining / tab change</p>
  <p><a href="https://i.stack.imgur.com/FbW1i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FbW1i.png" alt="enter image description here" /></a></p>