I have some code like that:
class MyApp(Ui_MainWindow):
def __init__(self):
pass
def setupUi(self, *args):
super(MyApp, self).setupUi(*args)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.doCheck)
def doCheck(self):
self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "Checking...", None, QtGui.QApplication.UnicodeUTF8))
# Code to do real checking here... (it's a network app)
# When check done, display result in a "QTextBrowser"
# ....
# Change text of Button to "Done!"
self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "Done!", None, QtGui.QApplication.UnicodeUTF8))
But the result not as I expect.
My app do network checking and display result ok, but the button did not change text to “Checking…” when the check begin; it’s only change text to “Done!” when everything is finished!
After changing button label you should run
QApplication::processEvents()to update UI with new label.Notice that your UI will be freezed while long task is running. To avoid this you should sometimes call
QApplication::processEvents()during long operation or run this operation in separateQThread.