我正在使用 PyQt5 编写一个管理销售订单的应用程序。创建或删除订单时,我想显示一个 marqee 样式的进度对话框以指示应用程序正在运行。我访问了很多帖子,其中的答案涉及使用 QThread。我试图实现它,但似乎我遗漏了一些东西。这是我的线程类。
class Worker(QThread):
finished = Signal()
def run(self):
self.x = QProgressDialog("Please wait..",None,0,0)
self.x.show()
def stop(self):
self.x.close()
在主窗口的初始化中,我创建了 self.worker=Worker()
现在删除条目的代码例如:
msg = MsgBox("yn", "Delete Order", "Are you sure you want to delete this order?") # Wrapper for the QMessageBox
if msg == 16384:
self.worker.start() ## start the worker thread, hoping to start the progress dialog
session.delete(order) ##delete order from db
session.commit() ##commit to db
self.change_view("Active", 8) ##func. clean up the table.
self.worker.finished.emit() ##emit the finished signal to close the progress dialog
结果是没有显示进度对话框。gui 只是冻结一两秒钟,然后条目删除,没有显示任何进度对话框。
对不起,我的代码很长,所以我不能在这里全部包含,我只是想看看我是否有什么严重的错误。