PDA

View Full Version : QGraphicsItem Opacity Mask



sdanahy
30th September 2009, 00:33
Does anyone know of a way to apply an opacity mask to a QGraphicsItem and it's children? Basically I'm looking to define per-pixel opacity like a bitmap's alpha channel. The feature looks like it will be available in Qt 4.6 via QGraphicsOpacityEffect, but I'm wondering if anyone knows of a solution for Qt 4.5.2.

Thanks!

Scott

wysota
30th September 2009, 09:28
If you mean an arbitrary item then I don't think it is possible. If you mean for your own items then by overriding mouse events and reimplementing the paint routine you should be able to do appropriate masking.

scascio
30th September 2009, 09:40
There is opacity features fo QGraphicsitem but with same opacity for all pixels. Not per-pixel defined.
You can can play with QGraphicsItem::opaqueArea to define a mask independtly of opacity.

I can't see any solution without overloading the paintEvent, draw into a QPixmap and defined you per-pixel opacity mask with alpha channel.

What is the goal of your need? Maybe another design cans take benefits of Qt features.

sdanahy
30th September 2009, 17:56
Thanks to both of you for the response.

All of the items in the view are mine, but the problem with just overriding the paint routine is that I want the mask to apply to the item's children as well (which are drawn after the item, if I understand correctly). I could propagate the opacity mask down the display tree, but then every item in my view would need a custom paint routine that would apply the mask. That seems awfully cumbersome so I was looking for a better way.

Thanks again for the ideas...

Scott