Qt and progressBar - how to update

不坏阿峰 onlydebian at gmail.com
Wed Jun 25 08:02:00 EDT 2014


在 2010年5月17日星期一UTC+7上午2时38分04秒,OMS写道:
> On 16 Maj, 20:52, Robert Kern <robert.k... at gmail.com> wrote:
> > On 2010-05-16 13:28 , OMS wrote:
> >
> >
> >
> > > I am quite new to Python and Qt and need very urgently advice on how
> > > to update Qt progressBar while executing a process. I have went thrugh
> > > number of 'google' stuff and saw different solution, hence none worked
> > > for me. The best idea I have seen is the usage of QThread and emiting
> > > signal from thread to MainWindow. I do not know however why the code I
> > > have written is not working. Most likely a stupid 'beginner related'
> > > error but as far as I am beginner I can't get it. There is a code
> > > below:
> >
> > > #!/opt/local/bin/python2.6
> >
> > > import os
> > > import sys
> > > import time
> > > from PyQt4 import QtCore
> > > from PyQt4 import QtGui
> >
> > > from uiTest import Ui_MainWindow
> >
> > > class MainWindow(QtGui.QMainWindow):
> > >      def __init__(self):
> > >          QtGui.QMainWindow.__init__(self)
> > >          self.ui=Ui_MainWindow()
> > >          self.ui.setupUi(self)
> > >          self.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"),
> > > self.runWorker)
> >
> > >      def runWorker(self):
> > >          self.worker = Worker()
> > >          self.connect(self.worker, QtCore.SIGNAL("progressUpdated"),
> > > self.updateWorkerProgress)
> > >          self.worker.start()
> >
> > >      def updateWorkerProgress(self, min, max, progress):
> > >          self.ui.progressBar.setMinimum = min
> > >          self.ui.progressBar.setMaximum = max
> > >          self.ui.progressBar.setValue = progress
> >
> > These should be
> >
> > self.ui.progressBar.setMinimum(min)
> > self.ui.progressBar.setMaximum(max)
> > self.ui.progressBar.setValue(progress)
> >
> > --
> > Robert Kern
> 
> Thanks. You have saved the day. I knew it must be something only
> greenhorn could do.
> 
> Once again thanks!

in ur code, u use self.progress in range(self.min, self.max) to define the progress bar time.

if want update prograss bar, base on how long dose the Qthread running take?  how to do ?



More information about the Python-list mailing list