PyQt Don't update shortcut

I have created a simple file transfer application using Paramiko and SFTP. I also wanted to have a status bar (QLabel) to inform the user when I upload / download stuff. So my load function looks something like this:

def upload(self):
        self.statusLabel.setText('Uploading')
        local = str(self.uploadLineEdit.text())
        filename = os.path.basename(local)
        remote = "/home/" + self.userName + "/testdata/" + filename
        self.ftp.put(local, remote)
        self.uploadedFileName = filename
        self.statusLabel.setText('Upload Finished')

      

Note that before starting the download, I change the status bar to download, and when the download is in progress, I change it to download.

What actually happens, however, is that the "Uploading" message never appears on the label - it just goes to "Upload Finished". I suspect this is because the changes only happen after the function returns.

How do I change the shortcut at the start of the download process?

+4


source to share


1 answer


You may need to force event handling after changing the label text. Try adding:

QApplication.processEvents()

      



after setting the label text.

Please note that for a reason unknown to me, PyQt and PySide have problems with processEvents

which sometimes need to be performed multiple times in order for it to take effect. So, if it doesn't work after adding one processEvents()

, try adding it twice or even multiple times.

+3


source







All Articles