title: How do I draw a semi-transparent rectangle in Qt?
body: <p>I'm trying to draw a semi-transparent rectangle on top of an image to act as a highlight.  Unfortunately, nothing I try seems to be able to perform the transparency effect I want.  Instead I just get solid filled rectangles, with no transparency.</p>
  
  <p>Here's what I'm doing right now:</p>
  
  <pre><code>void PageView::paintEvent(QPaintEvent *event)
  {
      QPainter painter(this);
      QImage img=...;
  
      painter.drawImage(0, 0, img);
      ...
      // draw a light blue, transparent rectangle to highlight
      QRect rect=...;
      painter.fillRect(rect, QColor(128, 128, 255, 128));
      ...
  }
  </code></pre>
  
  <p>Unfortunately, for me, this draws a <strong>solid</strong> blue rectangle, instead of the semi-transparent one I expect due to giving the <code>QBrush</code> an alpha value.</p>
  
  <p>I've also tried drawing to an intermediate <code>QImage</code> or <code>QPixMap</code>, playing around with <code>painter.setCompositionMode(...)</code>.  No luck so far.</p>
  
  <p>Thus my question: How can I convince Qt to draw a semi-transparent rectangle to my <code>PageView</code>?</p>
  
  <p><strong>EDIT</strong>: If it's relevant, I'm building this under Qt 4.8.1 on Windows.</p>