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?

Qt Code:
  1. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
  2. QWidget *widget)
  3. {
  4.  
  5. QRectF rect = boundingRect();
  6. painter->setBrush(Qt::red);
  7. painter->setOpacity(0.5);
  8. painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
  9. painter->drawEllipse(rect);
  10. }
To copy to clipboard, switch view to plain text mode