【问题标题】:How can i add a progress bar in splash screen pyqt4如何在启动画面pyqt4中添加进度条
【发布时间】:2017-09-11 06:27:40
【问题描述】:

我有一个简单的闪屏程序,如何在闪屏中添加Progress bar

from PyQt4.QtCore import *
from PyQt4.QtGui import *


class Form(QDialog):
    """ Just a simple dialog with a couple of widgets
    """
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        self.browser = QTextBrowser()
        self.setWindowTitle('Just a dialog')
        self.lineedit = QLineEdit("Write something and press Enter")
        self.lineedit.selectAll()
        layout = QVBoxLayout()
        layout.addWidget(self.browser)
        layout.addWidget(self.lineedit)
        self.setLayout(layout)
        self.lineedit.setFocus()
        self.connect(self.lineedit, SIGNAL("returnPressed()"),
                     self.update_ui)

    def update_ui(self):
        self.browser.append(self.lineedit.text())


if __name__ == "__main__":
    import sys, time

    app = QApplication(sys.argv)

    # Create and display the splash screen
    splash_pix = QPixmap('conti.jpg')
    splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
    splash.setMask(splash_pix.mask())
    splash.show()
    app.processEvents()

    # Simulate something that takes time
    time.sleep(2)

    form = Form()
    form.show()
    splash.finish(form)
    app.exec_()

提前致谢

【问题讨论】:

    标签: python pyqt pyqt4


    【解决方案1】:

    我搜索并找到了答案。我们可以在下面添加一个进度条

    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    import time
    
    
    class Form(QDialog):
        """ Just a simple dialog with a couple of widgets
        """
        def __init__(self, parent=None):
            super(Form, self).__init__(parent)
            self.browser = QTextBrowser()
            self.setWindowTitle('Just a dialog')
            self.lineedit = QLineEdit("Write something and press Enter")
            self.lineedit.selectAll()
            layout = QVBoxLayout()
            layout.addWidget(self.browser)
            layout.addWidget(self.lineedit)
            self.setLayout(layout)
            self.lineedit.setFocus()
            self.connect(self.lineedit, SIGNAL("returnPressed()"),
                         self.update_ui)
    
        def update_ui(self):
            self.browser.append(self.lineedit.text())
    
    
    if __name__ == "__main__":
        import sys, time
    
        app = QApplication(sys.argv)
    
        # Create and display the splash screen
        splash_pix = QPixmap('conti.jpg')
    
        splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
        # adding progress bar
        progressBar = QProgressBar(splash)
    
    
    
        splash.setMask(splash_pix.mask())
    
    
        splash.show()
        for i in range(0, 100):
            progressBar.setValue(i)
            t = time.time()
            while time.time() < t + 0.1:
               app.processEvents()
    
    
    
        # Simulate something that takes time
        time.sleep(2)
    
        form = Form()
        form.show()
        splash.finish(form)
        app.exec_()
    

    【讨论】:

      【解决方案2】:

      要关闭启动屏幕并打开主窗口,请使用:

      splash.close()
      mainWindow()  = MainWindows()
      mainWindow.show()
      

      请注意,使用 splash.finish() 将通过取消引用一些重要的 mainWindow 引用来终止应用程序。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多