[Qt-interest] QGraphicsItem and Threads

Brad Howes howes at ll.mit.edu
Tue Oct 20 16:25:49 CEST 2009


On Oct 20, 2009, at 3:34 AM, Ole Streicher wrote:

> for c, item in zip(self.colors, self.items):
>    item.brush().color().setRgb(c[0], c[1], c[2])
>


There is a setColor() method for QBrush, but after some thought, I  
realized that it is not as useful to you as I thought i was. The call  
to QAbstractGraphicsItem::brush() returns a shared copy of the QBrush  
held by the graphics item, but changing the color of the mutable  
QBrush (it is not const, at least not in 4.6 beta), will simply break  
the share and update only your local copy. You still have to place it  
back:

     item.setBrush( item.brush().setColor( color ) );

The sequence is thus (I think): get a shared copy via brush(), update  
the color making an unshared local QBrush, and then install the local  
QBrush via setBrush(). However, this may be one copy less than your  
method of sending the QBrush via a signal, which for 100K objects I  
bet is not insignificant.

Brad

PS: I'd appreciate if someone would chime in to correct my  
understanding of sharing semantics in Qt if I'm off-base here.

-- 
Brad Howes
Group 42
MIT Lincoln Laboratory • 244 Wood St. • Lexington, MA 02173
Phone: 781.981.5292 • Fax: 781.981.3495 • Secretary: 781.981.7420








More information about the Qt-interest-old mailing list