[PyKDE] Updating PyQt widgets question

Eric Williams eric at xoffender.de
Wed Nov 19 16:50:01 GMT 2003


Hello everybody,

(I posted this to comp.lang.python earlier, but I figured it would be more 
appropriate to post it here)

I've created a dialog in Qt Designer with a few text labels and 2 progress 
bars.  It's supposed to track the download of a directory full of files. I've 
noticed some weirdness with code similar to that below. Namely, the progress 
bars get updated correctly, but the text labels 'local_path' and 
'remote_path' don't change at all. 

class TestDialog(dlg_download):
        # test version of dialog, just plays with its widgets :-)

        def __init__(self):
                dlg_download.__init__(self)
                QObject.connect(self.btn_cancel, SIGNAL('clicked()'), 
						self, SLOT('close()'))
                QObject.connect(self.btn_start, SIGNAL('clicked()'), 
					 	 self.move_stuff)
                self.progressBar_thisfile.setTotalSteps(100)
                self.progressBar_allfiles.setTotalSteps(1000)

        def move_stuff(self):
                i = 0
                j = 0
                while j<1000:
                        if i < 100:
                                i+=1
                        else:
                                i=0
                        j+=1
                        self.progressBar_thisfile.setProgress(i)
                        self.progressBar_allfiles.setProgress(j)
                        self.remote_path.setText("DummyRemote %d" % i)
                        self.local_path.setText("DummyLocal %d" % j)
                        time.sleep(.1)





I've re-written my app so that it uses a QTimer and timerEvent method to 
update the widgets, and that the long-running routine (actually an FTP 
download) runs in a thread; that works like I expected. I guess my question 
is, is using a QTimer the 'correct' way to update widgets during an expensive 
routine like the one above? And what sort of widgets can be reliably updated 
from within a function?

Thanks for y'all's input!
Eric
-- 
 13:26:21  up 1 day, 24 min,  5 users,  load average: 0.31, 0.20, 0.16




More information about the PyQt mailing list