0
我有這樣的一些代碼:如何在長時間運行的任務中更改QPushButton的文本,並在任務完成時改回?
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))
但不是我期待的結果。 我的應用程序進行網絡檢查並顯示結果正常,但檢查開始時按鈕沒有將文本更改爲「正在檢查...」;只是將文字改爲「完成!」當一切都完成了!
它的工作原理!你真棒。 我也認爲它可以用QThread來完成,我嘗試過,但它很難。你知道一些關於它的好文檔嗎?非常感謝你! ; D – Locke
我只能建議你閱讀[官方文檔](http://qt-project.org/doc/qt-4.8/QThread.html)。 –
,你應該[也讀這個](http://qt-project.org/doc/thread-basics.html) – mata