how can i add a progress bar in splash screen pyqt4

  • Last Update :
  • Techknowledgy :

I searched and found the answer . we can add a progress bar as Below

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_()

To close the splash screen and open the main windows use:

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

Suggestion : 2

Updated date May 16, 2022

progressBar.Value=0. This will start the progressbar value from zero

public Form1() {
   InitializeComponent();
   progressBar.Value = 0;
}
private void Form1_Load(object sender, EventArgs e) {}

Then we have to create object of that windows application. Which we want to show after the splash screen and hide the splash screen.

private void timer1_Tick(object sender, EventArgs e) {
   progressBar.Value += 2; //we will increment the value of the progressbar by +2
   progressBar.Text = progressBar.Value.ToString() + "%";
   if (progressBar.Value == 100) {
      timer1.Enabled = false;
      login s = new login(); // create the object of of login
      s.Show(); // to show the login form
      this.Hide(); // to hide this screen 
   }
}

Suggestion : 3

Last Updated : 22 Apr, 2020

Syntax :

pbar = QProgressBar(self)

Suggestion : 4

Now that we have the progress bar, a download initiation button, and the download method, we should be all set. Here's the full code:,In the while loop, we would, in theory, keep checking where we were in the download process. Maybe seeing how many megabytes complete out of total megabytes, and then assigning that value to the completed variable.,That's all there is to it, but, if you run the window, you just have a boring progress bar. What do we actually do with this thing?,To add a progress bar, the code is painstakingly simple:

        self.progress = QtGui.QProgressBar(self)
        self.progress.setGeometry(200, 80, 250, 20)
1._
        self.progress = QtGui.QProgressBar(self)
        self.progress.setGeometry(200, 80, 250, 20)

So first, we need a simple button:

        self.btn = QtGui.QPushButton('Download', self)
        self.btn.move(200, 120)
        self.btn.clicked.connect(self.download)
3._
    def download(self):
       self.completed = 0

    while self.completed < 100:
       self.completed += 0.0001
    self.progress.setValue(self.completed)
    def download(self):
       self.completed = 0

    while self.completed < 100:
       self.completed += 0.0001
    self.progress.setValue(self.completed)