[PyQt] Re: PyQt4 and threading
rasky at develer.com
Sat Oct 24 16:27:55 BST 2009
On gio, 2009-10-15 at 10:00 +0200, Andreas Pakulat wrote:
> On 15.10.09 09:22:03, Ole Streicher wrote:
> > >> item.setBrush(QtGui.Brush(QtGui.QColor(...)))
> > Jason H <scorp1us at yahoo.com> writes:
> > > GUI operations can only be done in the main thread.
> > Is setting the brusch of a QGraphicsRectItem a GUI operation?
> Possibly, the scene.update() is definetly going to trigger GUI operations.
> > And, if yes:
> > What is the preferred way to provide huge GUI updates without getting
> > the user interface unresponsible? If I would put all the 100.000
> > QGraphicsRectItem color changes into the main thread, it would take many
> > seconds to process them, and in this time no other user activity
> > (updates on mouse move) can be made, what is inacceptable for the user.
> I don't think updating the brush of 100.000 is going to take multiple
> seconds. Qt won't redraw after each change, but only once you return to the
> event loop and then the brushes of all items have already changed.
> However if it really is too slow, you can simply split up the work into
> chunks and let the event loop run in between so the GUI keeps responsive.
> One way to achieve this is by using a QTimer which fires regularly and then
> work on a chunk in the connected slot.
Or just call qApp.processEvents() every once in a while during the main
loop. You can pair this with setUpdatesEnabled() calls if you don't want
to display partially-updated contents.
More information about the PyQt