title: How to make a QImage or QPixmap semi-transparent - or why is setAlphaChannel obsolete?
body: <p>4.7 and like to overlay two images on a qgraphicsview. The image on top shall be semi-transparent to allow to see through it. Initially both images are fully opaque. I expected some function for setting a global alpha-value for each pixel to exist, but it seems like there is no such function. The closest thing to it is QPixmap::setAlphaChannel(const QPixmap &amp; alphaChannel), which, however, is marked as obsolete since Qt-4.6. Instead the manual refers to the CompositionModes of QPainter, but I don't succeed to add transparency to an opaque image like I want. 
  Could anyone point me to a working example or share some code?</p>
  
  <p><strong>Edit:</strong>
  I'm almost sorry for having an own answer, now just a few hours after asking the question. 
  From this <a href="http://doc.trolltech.com/qq/qq17-compositionmodes.html" rel="noreferrer">article</a> I figured out that the following code does the job. I just wonder if this is considered "better" (which often translates to faster) than modifying the alpha values pixelwise.</p>
  
  <pre><code>QPainter p; 
  p.begin(image);
  p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
  p.fillRect(image-&gt;rect(), QColor(0, 0, 0, 120));
  p.end();            
  mpGraphicsView-&gt;scene()-&gt;addPixmap(QPixmap::fromImage(image-&gt;mirrored(false,true),0));  
  </code></pre>