[Qt-interest] QGraphicsItem and Threads

Ole Streicher ole-usenet-spam at gmx.net
Mon Oct 19 17:22:13 CEST 2009


Hi Brad,

Brad Howes <howes at ll.mit.edu> writes:
> First, try to determine where the slow-down occurs. If the brush is  
> the same for all of your objects, then it is a bit silly to have to  
> create 100K brushes; adapt your objects to use a common brush
> instead. 

Sure, but this is not the case. They are all (potentially) different.
 
> If not, try making the brush update an asynchronous signal/slot; that  
> way, you remain response as the application tries to deliver the  
> signal to the 100K objects. 

What I did now is to create the 100k Brushes asynchroniously and then
send all of them with one signal to the main thread that updates the
scene:
----------------------------8<-------------------------------------------
def __init__(self, ...):
    ...
    self.connect(self, QtCore.SIGNAL('newbrushes(PyQt_PyObject)'), 
                 self.newbrushes)

def async_update(self):
    brushes = [ QtGui.QBrush(QtGui.QColor(c[0], c[1], c[2]))
                for c, item in zip(self.colors, self.items) ]
    self.emit(QtCore.SIGNAL('newbrushes(PyQt_PyObject)'), brushes)

def newbrushes(self, brushes):
    for brush, item in zip(brushes, self.items):
        item.setBrush(brush)
    self.emit(QtCore.SIGNAL('changed()')) # --> leads to "scene.update()"
----------------------------8<-------------------------------------------

That works for me. Do I still need to use brush.moveToThread()
somewhere?

Best regards

Ole




More information about the Qt-interest-old mailing list