Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7947195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:21:48+00:00 2026-06-04T01:21:48+00:00

I have developed a GUI that is used to extract some data from a

  • 0

I have developed a GUI that is used to extract some data from a file. This process takes a long time. During the time when the program is processing the outside file (using subprocess.Popen), the main GUI will not be responsive (as expected). I wanted to add a message with an oscillating progress bar to the user to let him know the program is working and just to hang in there.
I implemented the progress bar as a QDialog and then call it before I call the long process. If I call the progress bar using the [dialog.exec_()] method, then the program waits for my response which is the outcome of the dialog. If I close the dialog the program continues on without the progress message I want to show. If I use the [dialog.show()] method, then all I see is an empty white window where the progress bar should be.
I tried multiple variations on this but to no success.

I am using:

Python 2.7.2
PyQt4: 4.9.1
Windows 7

Here is a sample code that shows the problem. Switch between dialog.exec() and dialog.show() to demo the problem.


import sys
import time
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import pyqtSignature

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class LongProcess(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(LongProcess, self).__init__(parent)
        self.setup(self)

    def setup(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(255, 208)
        MainWindow.setMinimumSize(QtCore.QSize(300, 208))
        MainWindow.setMaximumSize(QtCore.QSize(300, 208))
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        self.textEdit = QtGui.QTextEdit(self.centralwidget)
        self.textEdit.setObjectName(_fromUtf8("textEdit"))
        self.verticalLayout.addWidget(self.textEdit)
        self.pushButton = QtGui.QPushButton(self.centralwidget)
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.verticalLayout.addWidget(self.pushButton)
        MainWindow.setCentralWidget(self.centralwidget)

        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
        self.textEdit.setHtml(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
                                                           "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
                                                           "p, li { white-space: pre-wrap; }\n"
                                                           "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
                                                           "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">We want to run a long process in the background (calling a subprocess) and use an oscillating progress bar to show that the process is running. </span></p>\n"
                                                           "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"><br /></p>\n"
                                                           "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">When long process ends, we will close the oscillating progress bar. </span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "Run Long Process", None, QtGui.QApplication.UnicodeUTF8))
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    @pyqtSignature("")
    def on_pushButton_clicked(self):
        '''
            Simulate some long process to be performed.
            Before Long Process starts, show an oscillating progress bar to
            indiate process is running in background. 
        '''
        dialog = QtGui.QDialog()    
        progressBar = Ui_porcessProgress()
        progressBar.setupUi(dialog)
        dialog.show()
#        dialog.exec_()

        start = time.time()
        diff = 0
        while diff < 10:
            end = time.time()
            diff = end - start
            print (diff)

class Ui_porcessProgress(object):
    def setupUi(self, porcessProgress):
        porcessProgress.setObjectName(_fromUtf8("porcessProgress"))
        porcessProgress.setWindowModality(QtCore.Qt.ApplicationModal)
        porcessProgress.resize(329, 81)
        porcessProgress.setMinimumSize(QtCore.QSize(329, 81))
        porcessProgress.setMaximumSize(QtCore.QSize(329, 81))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/WFT/wftlogo2.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        porcessProgress.setWindowIcon(icon)
        porcessProgress.setModal(True)
        self.verticalLayout = QtGui.QVBoxLayout(porcessProgress)
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        self.label = QtGui.QLabel(porcessProgress)
        self.label.setObjectName(_fromUtf8("label"))
        self.verticalLayout.addWidget(self.label)
        self.porcessProgressBar = QtGui.QProgressBar(porcessProgress)
        self.porcessProgressBar.setMaximum(0)
        self.porcessProgressBar.setProperty("value", 10)
        self.porcessProgressBar.setTextVisible(False)
        self.porcessProgressBar.setObjectName(_fromUtf8("porcessProgressBar"))
        self.verticalLayout.addWidget(self.porcessProgressBar)
        porcessProgress.setWindowTitle(QtGui.QApplication.translate("porcessProgress", "Please wait...", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("porcessProgress", "Time History data extraction from ODB file in progress...", None, QtGui.QApplication.UnicodeUTF8))
        QtCore.QMetaObject.connectSlotsByName(porcessProgress)
#
#------------------------------------------------------------------------------ 
#
def main():
    app = QtGui.QApplication(sys.argv)
    mainWindow = LongProcess()
    mainWindow.show()
    sys.exit(app.exec_())
#
#------------------------------------------------------------------------------ 
#
if __name__ == "__main__":
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:21:50+00:00Added an answer on June 4, 2026 at 1:21 am

    This is kinda quackery way to fix this issue.

    If you want to do this right way, You should put while loop inside of QThread,
    and using Signal and slot to update QProgressbar.

    But this will fix your issue just fine for now.

    Missing pieces were,

    1. set maximum value of progressBar setMaximum(value)
    2. add code updating progressBar setValue(value)
    3. Enforce Event Process using QApplication.processEvents()

    Quick fix :

    #Add QApplication on top #################
    from PyQt4.QtGui import QApplication
    ##########################################
    def on_pushButton_clicked(self):
            '''
                Simulate some long process to be performed.
                Before Long Process starts, show an oscillating progress bar to
                indiate process is running in background. 
            '''
            dialog = QtGui.QDialog()    
            progressBar = Ui_porcessProgress()
            progressBar.setupUi(dialog)
            dialog.show()
            #dialog.exec_()
    
            start = time.time()
            diff = 0
            while diff < 10:
                end = time.time()
                diff = end - start
    
    
                ################################################### 
                #add routine to update progressBar value
                progressBar.porcessProgressBar.setValue(diff)
                QApplication.processEvents()
                #add routine to update progressBar value 
                ###################################################
    
    
                print (diff)
    
    class Ui_porcessProgress(object):
        def setupUi(self, porcessProgress):
            porcessProgress.setObjectName(_fromUtf8("porcessProgress"))
            porcessProgress.setWindowModality(QtCore.Qt.ApplicationModal)
            porcessProgress.resize(329, 81)
            porcessProgress.setMinimumSize(QtCore.QSize(329, 81))
            porcessProgress.setMaximumSize(QtCore.QSize(329, 81))
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/WFT/wftlogo2.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            porcessProgress.setWindowIcon(icon)
            porcessProgress.setModal(True)
            self.verticalLayout = QtGui.QVBoxLayout(porcessProgress)
            self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
            self.label = QtGui.QLabel(porcessProgress)
            self.label.setObjectName(_fromUtf8("label"))
            self.verticalLayout.addWidget(self.label)
            self.porcessProgressBar = QtGui.QProgressBar(porcessProgress)
    
            ###########################################
            ####Set max value of progress bar
            self.porcessProgressBar.setMaximum(10)
            ############################################
    
            self.porcessProgressBar.setProperty("value", 10)
            self.porcessProgressBar.setTextVisible(False)
            self.porcessProgressBar.setObjectName(_fromUtf8("porcessProgressBar"))
            self.verticalLayout.addWidget(self.porcessProgressBar)
            porcessProgress.setWindowTitle(QtGui.QApplication.translate("porcessProgress", "Please wait...", None, QtGui.QApplication.UnicodeUTF8))
            self.label.setText(QtGui.QApplication.translate("porcessProgress", "Time History data extraction from ODB file in progress...", None, QtGui.QApplication.UnicodeUTF8))
            QtCore.QMetaObject.connectSlotsByName(porcessProgress)
    #
    #------------------------------------------------------------------------------ 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Swing GUI that I developed Netbeans Matisse in Linux. For some
I have developed some mysql queries for my application, and created indexes and used
We have a command line application that could benefit from a GUI. We want
I have developed a small application using Perl/Tk. The application will fetch data from
I have a small GUI application developed with netbeans. I used the 'clean and
I have developed direct3D video rendering library that is used for rendering video in
I have developed a GUI application in NetBeans and I want to share it
I have developed a multithreaded web application that runs in Tomcat. But I cannot
I have developed a PHP application that processes relatively large text files, and stores
I have developed some classes with similar behavior, they all implement the same interface.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.