I have a simple pyqt5 application writing numbers inside a textBrowser Widget. But when the focus of the pyqt5 window is lost in other words when I click outside the window during the process it stops writing to the textBrowser until the method finishes. How can I fix that?
Code:
import sys
import time
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5.uic import loadUi
from logger import Logger
class MainWindow(QDialog):
logger = None
def __init__(self, logger: Logger = None):
super(MainWindow, self).__init__()
loadUi('main.ui', self)
self.widget = QtWidgets.QStackedWidget()
self.widget.setFixedWidth(600)
self.widget.setFixedHeight(400)
self.widget.addWidget(self)
self.logger = logger
self.widget.show()
self.start_task_button.clicked.connect(self.start_task)
def start_task(self):
numbers = [1,2,3,4,5,6]
self.logger.log("start")
for i in numbers:
time.sleep(3)
self.logger.log(i)
def log(self, message):
self.textBrowser.append(message)
self.textBrowser.repaint()
print(message)
# init ui
app = QApplication(sys.argv)
logger = Logger()
main_window = MainWindow(logger)
logger.register(main_window)
main_window.show()
app.exec_()
UI: pastebin of the loaded ui file: https://pastebin.com/h8Bs5r5K
Image: As you can see the console shows already 5 while the textBrowser only shows 1 (the moment I clicked outside the window) it should be the same.