progress = QtGui.QProgressDialog("Parsing Log", "Stop", 0,numberOfLinesInFile , self)
progress.setWindowModality(QtCore.Qt.WindowModal)
for lineNumber, line in enumerate(file):
# yield a bit to the Qt UI handler
QtGui.QApplication.processEvents()
progress.setValue(lineNumber + 1) # lineNumber is zero-based so need the plus one to match the more literal numberOfLinesInFile
if progress.wasCanceled():
progressWasCancelled = True
break
# ...read and parse lines from file (20mb takes ~10 seconds)
# crank the progress bar through to completion to get rid of it
# this seems to forgo the opportunity to use progress.wasCanceled() subsequently?
progress.setValue(numberOfLinesInFile)
if not progressWasCancelled:
self.updateTable(self.requestRoster)
此後,無論進度對話是否被取消,隱藏進度對話框(它滑回工具欄)。但是,如果我切換應用程序(Mac上的'命令選項卡'),然後切換回我的應用程序,QProgressDialog的一個幻影就在主應用程序窗口的前面!它的進度條是100%,停止按鈕是藍色的,但沒有脈衝。它沒有反應。如果我移動應用程序窗口,它會消失。QProgressDialog屍體徘徊 - 有時
如果我在progress.setValue(numberOfLinesInFile)之後調用progress.destroy(),這似乎有幫助。但似乎令人擔心的是從文檔中複製示例並被咬傷,而我不知道destroy()的後果。
我正在使用PySide,我切換到PyQt和相同的東西。
此外,有時progress.setValue(numberOfLinesInFile)
導致後續讀取progress.wasCancelled()
返回false(但有時它返回true!),這就是爲什麼我設置我自己的。它的隨機性令人不安。
我在Mac 10.6.8,Qt 4.8.2,Python 2.7。試用PySide 1.1.0和PyQt 4.9.4。
我這樣做全錯嗎?
請不要問兩個不相關的問題於一身。您應該將有關進度欄的部分作爲單獨的問題發佈。 – sashoalm
@satuon。這裏肯定沒有兩個不相關的問題,所以我已經把你的編輯推回去了。在不進行太多細節的情況下,進度對話框中的'setValue()'函數不僅僅是更新進度條小部件,它的功能更多。 – ekhumoro