pyqt5 等待界面 (QMovie 加载 gif)

2023-02-06 10:11:09 浏览数 (1)

loading.gif是从 http://www.sucaijishi.com/gif-11-57-1.html找的图

代码语言:javascript复制
class LoadingProgress(QtWidgets.QDialog):
    update_signal = QtCore.pyqtSignal(bool)

    def __init__(self, parent=None):
        super(LoadingProgress, self).__init__(parent)
        self.value = 0
        self.update_signal.connect(self.update_progress)
        vbox = QtWidgets.QVBoxLayout(self)
        self.steps = [f"连接服务器中({TIMEOUT}s)...",
                      "发送数据中...",
                      "接收数据中...",
                      "解析数据中..."]
        self.movie_label = QtWidgets.QLabel()
        self.movie = QtGui.QMovie("images/loading.gif")
        self.movie_label.setMovie(self.movie)
        self.movie.start()
        self.progress_label = QtWidgets.QLabel()
        self.label_update()

        vbox.addWidget(self.movie_label)
        vbox.addWidget(self.progress_label)
        self.setLayout(vbox)
        # self.exec_()
        
    def label_update(self):
        self.progress_label.setText(self.steps[self.value])

    def update_progress(self, boolean: bool) -> None:
        self.value  = 1
        if boolean and self.value < len(self.steps):
            self.label_update()
        else:
            self.close()

阻塞调用:

代码语言:javascript复制
self.exec_()

非阻塞调用:

代码语言:javascript复制
self.show()

源代码就不发了, 今天就发v2.6的更新, 顺带发了

0 人点赞