【发布时间】:2012-11-28 05:59:31
【问题描述】:
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%,停止按钮为蓝色但不闪烁。它没有反应。如果我移动应用程序窗口,它就会消失。
如果我在 progress.setValue(numberOfLinesInFile) 之后调用 progress.destroy() 似乎有帮助。但是从文档中复制示例并被咬似乎令人担忧,而且我不知道 destroy() 的后果。
我使用的是 PySide,我切换到 PyQt 和同样的东西。
另外,有时progress.setValue(numberOfLinesInFile) 会导致后续读取progress.wasCancelled() 返回false(但有时它返回true!)这就是我设置自己的progressWasCancelled 的原因。它的随机性令人不安。
我使用的是 Mac 10.6.8、Qt 4.8.2、Python 2.7。尝试使用 PySide 1.1.0 和 PyQt 4.9.4。
我做错了吗?
【问题讨论】:
-
请不要把两个无关的问题合二为一。您应该将有关进度条的部分作为单独的问题发布。
-
@satuon。这里肯定没有两个不相关的问题,所以我已经回滚了你的编辑。无需赘述,进度对话框中的
setValue()函数所做的很多不仅仅是更新进度条小部件。