创建进度条对话框
以下代码在接受到信号时会在主窗口下创建一个进度条对话框,进度条为循环滚动的忙碌状态
代码块1:
@Slot
def process_bar(self):
dialog = QProgressDialog(minimum=0, maximum=0, parent=self.window)
dialog.resize(400, 60)
dialog.setCancelButton(None)
dialog.setWindowModality(Qt.ApplicationModal)
dialog.show()
QCoreApplication.processEvents()
下面我们来加工以下,在进度条对话框弹出之后添加我们的计算逻辑,这里我用个while循环来阻塞线程
代码块2:
def time_test(sleep_time):
from datetime import datetime
start_time = datetime.now()
while (datetime.now() - start_time).seconds < sleep_time:
pass
添加计算逻辑,阻塞进度条显示
在代码块1中,QCoreApplication.processEvents()之后调用time_test()
代码块3:
@Slot
def process_bar(self):
dialog = QProgressDialog(minimum=0, maximum=0, parent=self.window)
dialog