1

I have a QGraphicsScene with several MyQGraphicsItems, which I subclassed from QGraphicsItem, inside of it. Inside the paint event of MyQGraphicsItem, I have

painter->drawImage(image_rect, m_image);

so every MyQGraphicsItem presents a QImage to the user. m_image is simply a QImage that supports an alpha channel:

m_image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied)

The user can drag these items around such that regions of two or more items may overlap at any time. Whenever two or more MyQGraphicsItems overlap, I want to set the transparency of the overlapping region such that all the items are equally visible in that region (but the non-overlapping regions should remain opaque).

Currently, I have to compute the overlap manually, and then use painter->setOpacity(opacity);. This is inconvenient and difficult. After searching the internet I feel that using QPainter::CompositionMode is the correct way to go, but I have no idea how to use this.

I looked at this example, but my case is different in the sense that I have completely separate items that are overlapping, and thus I cannot paint them all with a single QPainter. Any suggestions would be greatly appreciated.

hjweide
  • 11,893
  • 9
  • 45
  • 49

0 Answers0