View Full Version : PyQt loading progressbar?
Hi,
I have some os.system commands in my app that take some time executing.
I'd like to display a progress bar over my main windows while the commands are running.
It would also be nice if i could write text to it according to execution state, like "adjusting image", "running recognition", "deleting tmp files"
How can I do this in Qt and python?
Did you even try to do a Google search? One search later I found this:
http://zetcode.com/tutorials/pyqt4/widgets/
Jump down to the part about ProgressBar.
Did you even try to do a Google search? One search later I found this:
http://zetcode.com/tutorials/pyqt4/widgets/
Jump down to the part about ProgressBar.
Of course I tried googleing.
The problem is I don't have timed events.
I can't know how long does it take for commands to execute.
I need a progress bar that will load "indefinitely" (from left to right, and back) until the commands are over and I have to close the progress bar manually.
A little more Google and I find the following:
If you set minimum, maximum and value all to zero, then you will get the animation. Then call setProgress().
After this you can just change the text after the different tasks end.
And this is the documentation that describes the behaviour:
http://doc.qt.nokia.com/4.6/qprogressbar.html
Thanks for your help!
Do you have any idea how can I start the progress bar in center of screen, and lock focus on it.
So the user can't click anything while the progress bar is loading
Thanks for your help!
Do you have any idea how can I start the progress bar in center of screen, and lock focus on it.
So the user can't click anything while the progress bar is loading
I think the Maemo 5 way of doing things is put the progress bar widget in a dialogue box (see updating in Application Manager, moving files in File Manager, etc.)
I think the Maemo 5 way of doing things is put the progress bar widget in a dialogue box (see updating in Application Manager, moving files in File Manager, etc.)
Yes, just use the standard QProgressDialog.
noobmonkey
2010-05-04, 15:52
took me ages to get something that works for me -
progress = QtGui.QProgressDialog("Please Wait", "Cancel", 0, 100, MainWindow)
progress.setWindowModality(QtCore.Qt.WindowModal)
progress.setAutoReset(True)
progress.setAutoClose(True)
progress.setMinimum(0)
progress.setMaximum(100)
progress.resize(800,220)
progress.setWindowTitle("Loading Something")
progress.show()
progress.setValue(0)
<<do something>>
progress.setValue(20)
<<do something>>
etc.....
progress.setValue(100)
progress.hide()
I tried your code, but it doesn't work for me.
I have a specific situation.
There are two windows, application and the camera app
When camera app is closed, the image goes trough processing.
That is where I need the progress dialog, because it takes some time.
The ting is that the process starts right after the camera app is closed. So I get back to the "multitask view" not the actual application. Maybe that is the problem?
The program that opens the ProgressDialog owns it via its main window. If your application is not in focus while opening the dialog, this might confuse the Qt mechanics. But I wouldn't think that this is hard to solve. Applications continue to run and update their windows when in "Task view".
noobmonkey
2010-05-04, 16:18
yeah - i had to load my mainwindo - then do the qt progress bar as part of that - was tricky :P
the only thing I cant get working is the "infinite lopping"
I set everything to 0
and call setProgress, but it gives the error that QProgressDialog has no attribute
actually its not working well
at first its just blank dialog
than the 0% appears
and hangs at 0 until its finished
it closes fine
but doesn't progress
Did you read the documentation?
http://doc.qt.nokia.com/4.6/qprogressdialog.html
It looks very much like the it will not behave like a normal ProgressBar. But you'll have to read.
yes I have read it
and am no closer to fixing my problem
noobmonkey
2010-05-04, 17:16
healthchecks does work - and not sure why if yours isnt?
code is here - http://gitorious.org/healthcheck/healthcheck
I can't figure it out
Here is my code
progress = QtGui.QProgressDialog("Please Wait", "Cancel", 0, 100, self.mainForm)
progress.setWindowModality(QtCore.Qt.WindowModal)
progress.setAutoReset(True)
progress.setAutoClose(True)
progress.setMinimum(0)
progress.setMaximum(100)
progress.resize(800,220)
progress.setWindowTitle("Running OCR engine")
progress.show()
progress.setValue(0)
os.system('convert '+ lastPic+ ' test.tif')
progress.setValue(30)
os.system('tesseract test.tif test')
progress.setValue(100)
progress.hide()
Btw. the code is run in a controller class, so I pass the parent as self.mainWindow, which is a reference to mainWindow class
attila77
2010-05-04, 17:45
Guys - QProgressDialog is asynchronous, you need to either update via signals, asynchronously, or manually force the redraw. Also, with 4.6, if you just want to say I'm busy, and not a real progress bar, there is a window attribute for the little circular busy indicator.
how can i force it to redraw?
I just did:
progress = QtGui.QProgressDialog(self)
progress.setWindowTitle('Loading')
progress.setValue(10)
...
progress.setValue(20)
...
progress.setValue(100)
The dialog appears after the first setValue() and disappears when the value is set to 100 (the default maximum) - that's all just the default behaviour.
Hi,
You have to call Qapplication::processEvents() continiously in a loop to let the main event loop redraw progress after you set it.
progress.setValue(1)
for(int i=0;i<100;i++)
{
//do something, copy a file etc.
progress.setValue(x); //x is some value corresponding to your progress.
Qapplication::processEvents(); //your progress bar would move according to x.
}
Hi,
You have to call Qapplication::processEvents() continiously in a loop to let the main event loop redraw progress after you set it.
Not if it's modal - setValue() will call QApplication::processEvents() automatically then.
It works a lot better with .processEvents()
It actually gets displayed like it should.
Still can't get the "infinite looping" to work
attila77
2010-05-07, 14:10
AFAIK you need to set both minimum and maximum to 0, but on Qt4.5 for Maemo IIRC that had some styling issues.
I have given up on these Qt bugs.
Got it working with creating my own progress dialog.
Progress bar (when set to 0) works fine.
vBulletin® v3.8.8, Copyright ©2000-2025, vBulletin Solutions, Inc.