[Qt-interest] QGraphicsItem and Threads

Ole Streicher ole-usenet-spam at gmx.net
Tue Oct 20 09:34:05 CEST 2009


Hi Brad,

Brad Howes <howes at ll.mit.edu> writes:
> On Oct 19, 2009, at 11:22 AM, Ole Streicher wrote:
> Based on your code, an even better approach would be to just emit the  
> colors and not the QBrush objects, and have the items just update  
> their brush to use the new color. You save on object creation /  
> destruction.

What do you mean?

What I tried in the beginning:

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

It worked for Qt 4.5.0 but failed for 4.5.3.
When looking into the documentation, I found out that "QBrush.color()"
returns a "const QColor &" (in the C++ interface), so the call of
setRgb() will fail on that (as far as I understand C++...). A
"item.brush(QColor(c[0], c[1], c[2])" also will fail since
QAbstractGraphicsItem.brush() returns a "const QBrush &". Thus, I need
to create a new QBrush instance, using a new QColor instance if I want
to change the color.

I would really like to save this stupid object creation, but I guess
this is what the Qt developers wanted to forbid for some reason (Why??)

Regards

Ole




More information about the Qt-interest-old mailing list