[PyQt] Re: PyQt4 and threading

Andreas Pakulat apaku at gmx.de
Thu Oct 15 09:00:27 BST 2009


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.

Andreas 

-- 
Chess tonight.


More information about the PyQt mailing list