I have developed an app (my first in PyQt) that downloads a log file from a networked printer and it is working. The only piece I am now missing is figuring out a way to let the user know the download is happening because the log files can potentially be quite large and take several minutes.
I have tried using the status bar's showMessage() method but nothing shows up until after the download has completed. I realize now this is probably because my event handler is blocking any UI updates. So my question is in two parts:
- Is there a way to force the UI update in the middle of an event handler?
- If this is not possible, is there a better way to show some sort of feedback to say "something is happening, don't click that button again"?
Thank you.
The relevant parts of my code (yes, I used qt-designer):
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
...
self.pushButton = QtWidgets.QPushButton(self.layoutWidget)
self.pushButton.setFlat(False)
self.pushButton.setObjectName("pushButton")
...
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
def do_dl():
session = login(device, id, pw)
if session:
ui.statusbar.showMessage("Beginning download ...")
download(session)
...
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
ui.pushButton.clicked.connect(do_dl)
MainWindow.show()
sys.exit(app.exec_())