You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
1 year ago
|
import sys
|
||
|
import time
|
||
|
from PyQt5.QtWidgets import QApplication, QWidget, QDialog, QVBoxLayout, QPushButton, QLabel, QProgressBar
|
||
|
from PyQt5.QtCore import Qt, QThread, pyqtSignal
|
||
|
|
||
|
class LoadDataThread(QThread):
|
||
|
progress = pyqtSignal(int)
|
||
|
|
||
|
def run(self):
|
||
|
for i in range(101):
|
||
|
time.sleep(0.05) # 模拟数据加载过程
|
||
|
self.progress.emit(i)
|
||
|
|
||
|
class LoadingDialog(QDialog):
|
||
|
def __init__(self):
|
||
|
super().__init__()
|
||
|
self.initUI()
|
||
|
|
||
|
def initUI(self):
|
||
|
vbox = QVBoxLayout()
|
||
|
|
||
|
self.label = QLabel("加载数据中,请稍后...", self)
|
||
|
self.progressBar = QProgressBar(self)
|
||
|
|
||
|
vbox.addWidget(self.label)
|
||
|
vbox.addWidget(self.progressBar)
|
||
|
|
||
|
self.setLayout(vbox)
|
||
|
self.setWindowTitle('数据查询')
|
||
|
self.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.CustomizeWindowHint)
|
||
|
self.setModal(True)
|
||
|
|
||
|
def updateProgress(self, value):
|
||
|
self.progressBar.setValue(value)
|
||
|
|
||
|
class LoadingDataWidget(QWidget):
|
||
|
def __init__(self):
|
||
|
super().__init__()
|
||
|
|
||
|
def loadData(self):
|
||
|
self.loadingDialog = LoadingDialog()
|
||
|
|
||
|
# 创建和启动数据加载线程
|
||
|
self.loadThread = LoadDataThread()
|
||
|
self.loadThread.progress.connect(self.loadingDialog.updateProgress)
|
||
|
self.loadThread.finished.connect(self.onLoadingFinished)
|
||
|
|
||
|
self.loadThread.start()
|
||
|
self.loadingDialog.exec_()
|
||
|
|
||
|
def onLoadingFinished(self):
|
||
|
self.loadingDialog.accept()
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
app = QApplication(sys.argv)
|
||
|
ex = LoadingDataWidget()
|
||
|
sys.exit(app.exec_())
|