使 QProgressDialog 更新,值也不变
我有一个进度,我用 PyQt4 中的 QProgessDialog “管理”。基本上,我有一个像这样的循环:
while progressThread.isRunning():
self.progressDialog.setRange(0, self.progressTotal_)
self.progressDialog.setValue(self.progress_)
del self.progressDialog
ProgressThread 更新变量 self.progessTotal_ 和 self.progress_
当 Progress_ 的值不断变化时,这工作得很好。 但对于某些任务,情况并非如此(因为进度报告不够详细)。
结果是,progressDialog 显示一个灰色窗口,直到发生变化。我可以在 while 循环中插入一些内容,强制 ProgressDialog 更新也没有任何变化吗?
谢谢! 内森
I have a progress which I "mintor" with a QProgessDialog in PyQt4. Basicly, I have a loop like this:
while progressThread.isRunning():
self.progressDialog.setRange(0, self.progressTotal_)
self.progressDialog.setValue(self.progress_)
del self.progressDialog
The progressThread upades the variables self.progessTotal_ and self.progress_
This works pretty well, when the value of progress_ changes constantly.
But for some task, this is not the case (because the progress report is just not that detailed).
The result is, the progressDialog showing a gray window until something changes. Can I insert something in the while loop, that forces the progressDialog to upadate also nothing changes?
Thanks!
nathan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将更新信号从线程连接到进度对话框。您正在用循环阻塞 UI 线程。您可以在循环中添加 QApplication::processEvents 调用,但只要不阻塞 UI 线程就可以了。
You should connect an update signal from your thread to the progress dialog. You're blocking the UI thread with your loop. You could add a QApplication::processEvents call in the loop, but just don't block the UI thread and you'll be fine.