PDA

View Full Version : composition of qgraphics items on qscene graph



qtboy
27th June 2015, 04:49
I am drawing multiple qgraphics items on mouse moves in qgraphics scene. The items have alpha(opacity)=50%. But, I want the items to have composition(source over), so that overlapping region does not become dark. How can I do that?

I am drawing the items using the paint functions and after adding to the scene, they just overlap and the overlapping region becomes darker. How can I avoid this. I also need to implement in an efficient way. I may have thousands of items on the scene( actually the items will be small circles/dots created during mouse moves).


Can somebody suggest me how can I do it? I guess, in the paint function of the qgraphicsitem, I need to read the qimage of the scene and do some manipulation inside it. Or is there any other alternative?



void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{

QRectF rect = boundingRect();
painter->setBrush(Qt::red);
painter->setOpacity(0.5);
painter->setCompositionMode(QPainter::CompositionMode_Sourc eOver);
painter->drawEllipse(rect);
}