Search code examples
pythonwindowspython-3.xpyqtlabel

PyQt Label not changing text


I have this code running on a PyQt window on windows:

    try:
        self.actorUser.findIdfFiles(pathToFolder)
        msg = "Processando arquivos..."
        self.processingLabel.setText(msg)

        self.actorUser.runSimulation(pathToFolder, pathToEpw)

Inside the "runSimulation" code I start a subprocess using the method "call". This blocks my GUI and at the title of the window appears "Python stopping responding", but if I wait a little bit the subprocess finishes normally, and the label is finally changed. But what I want is that the label have is text really changed before the subprocess started. What can I do??


Solution

  • Qt (and most UI frameworks) don't update the display as soon as values are set, only when they are told to repaint.

    What you need to do is add a call

    QtGui.QApplication.processEvents()
    

    before your long-running subprocess, to make it process all pending events.