[Qt-interest] QGraphicsItem and Threads
Jason H
scorp1us at yahoo.com
Tue Oct 20 18:39:10 CEST 2009
Well you bring up a good point. To change the color of many items, they probably have to use a shared brush. Then it is just a matter of fast assignment of one single brush, but then you have to iterate over all the objects using that brush, and reset the brush to the shared brush.
You may have to reimplement the item class to allow the use of a brush pointer. This should get around the implicit-sharing semantics.
----- Original Message ----
From: Brad Howes <howes at ll.mit.edu>
To: "qt-interest at trolltech.com Interest" <qt-interest at trolltech.com>
Sent: Tue, October 20, 2009 10:25:49 AM
Subject: Re: [Qt-interest] QGraphicsItem and Threads
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
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list