[PyQt] pyqt4 problem with label.setText timing within loops
phil at riverbankcomputing.com
Tue Feb 16 09:47:46 GMT 2010
On Tue, 16 Feb 2010 00:12:47 -0500, Dan Cherry <dan.s.cherry at gmail.com>
> I'm trying to run a simple 'for' loop to execute some external programs
> (ripping tracks with cdparanoia/lame, but I've stripped the problem down
> to bare essentials that demonstrate the problem).
> Each loop should update a gui label with the current loop number. The
> setText statement is within the 'for' loop, but the gui doesn't get
> updated until the loop is either completed or several iterations into
> the complete loop. The loop works, but the updates to the label do not.
> The Gui was created with QTDesigner, and I'm using python 2.6.4 on
> Ubuntu 9.10.
> The statements that are crucial follow below, and I've attached the two
> py files if you care to see the full code.
> Any suggestions for getting the label.setText statements to update the
> gui with each loop iteration, would be appreciated.
> Dan Cherry
> def runloop(self):
> self.ui.label.setText('Begin Loop') ## <--doesn't update before
> for i in range(1,6):
> self.ui.label.setText('loop %s' % i) ## <--doesn't update
> for each loop - but does update after the loop completes
> rval = self.loop(i)
> def loop(self, loop_no):
> print loop_no ## <--the print statements display properly as
> the loop progresses
The GUI will only get updated when the event loop runs. Call
QCoreApplication.processEvents() after setText().
More information about the PyQt