[Qt-interest] QGraphicsOpacityEffect performance worse than QGraphicsItem::setOpacity()

Josiah Bryan jbryan at productiveconcepts.com
Thu Oct 15 14:26:11 CEST 2009


Samuel Rødal wrote:
> Josiah Bryan wrote:
>> I'm incredibly excited about the new QGraphicsEffect "module" in Qt 
>> 4.6. Since the release of the beta last night (today?), I've 
>> integrated two of the effects (opacity and drop shadow) into the 
>> project I've been working on for the past two months 
>> (http://code.google.com/p/dviz/).
> 
> QGraphicsOpacityEffect is usually going to be quite a bit slower than 
> just setting the opacity on the item. The use case for 
> QGraphicsOpacityEffect is when you want to apply opacity to a group of 
> overlapping items, or to an item whose paint() function draws several 
> overlapping shapes. By just using QGraphicsItem::setOpacity() the 
> opacity will be set on the painter, and thus each individual paint 
> command will be affected by the opacity. Thus, if you have a green item 
> on top of a red item, you will see parts of the red item when setting 
> opacity to 50 %, since first the red item is drawn with 50 % opacity and 
> then the green item. QGraphicsOpacityEffect on the other hand paints the 
> whole graphics item (+ children) to a temporary pixmap, and then draws 
> the pixmap with opacity set. This will naturally be quite a bit slower 
> than using setOpacity().

Precisely what I wanted to use the opacity effect for - multiple items 
overlapping. In my scene, I've got two "root" items - one for the 
current slide, one for the next slide. I only use one opacity effect - 
for the "root" item that is fading out (zValue on top). This slowly 
reveals the next slide underneath.


> I wouldn't recommend using graphics effects on other than small graphics 
> items when using the raster paint engine. Prefer to set a QGLWidget as 
> viewport on the QGraphicsView to improve the performance of the graphics 
> effects. Also, when using a QGLWidget I'd recommend using a smaller 
> amount of graphics effects covering a larger area, instead of a lot of 
> individual graphics effects, as each graphics effect requires binding 
> and releasing an OpenGL framebuffer object, which has a slight overhead 
> cost.

I used the QGLWidget as the viewport for all my tests. When testing the 
dropshadow effect, it was the only effect and the only object in the 
root object (other the the opacity effect on the root object).

It just seems odd that the performance of these effects is so 
*extreemly* below par that they are hardly usable for any sort of user 
interface or "live" scenes.

For the record, the application is using the raster graphics system 
(QApplication::setGraphicsSystem("raster")), while the QGraphicsView 
viewport uses a QGLWidget: setViewport(new 
QGLWidget(QGLFormat(QGL::SampleBuffers))).


Regards,
-josiah




More information about the Qt-interest-old mailing list