title: Clear Transparent Background for QWidget
body: <p>I have a widget as on overlay for another widget. The transparency works fine, as long as I don't clear the background of the overlay.</p>
  
  <p><img src="https://i.stack.imgur.com/K6UTJ.png" alt="Overlay still transparent"></p>
  
  <p>But I have to clear the widget to acutalize the displayed "effects". I tried to solve the inital problem (the background getting the default color) like described in <a href="https://stackoverflow.com/questions/20848594/erasing-painted-areas-from-translucent-widgets-in-qt">20848594</a>, but except changing the color to black it had no effect...</p>
  
  <p><img src="https://i.stack.imgur.com/du9xR.png" alt="After &quot;Clearing&quot;"></p>
  
  <p>Has anyone an idea why the widget which should be transparent does not display the underlaying widget(s)?</p>
  
  <hr>
  
  <p>Here the code:</p>
  
  <pre><code>SudokuMarkerOverlayWidget::SudokuMarkerOverlayWidget(QWidget* parent, uint const fieldSize) : QWidget(parent)
  {
      // Translucent should be the correct one
      setAttribute(Qt::WA_TranslucentBackground);
      //setAttribute(Qt::WA_NoSystemBackground);
      setAttribute(Qt::WA_TransparentForMouseEvents);
  
      ...
  }
  
  void SudokuMarkerOverlayWidget::paintEvent(QPaintEvent*)
  {
      QPainter painter(this);
      painter.setRenderHint( QPainter::Antialiasing );
  
      // Tried this too, no difference
      // painter.setCompositionMode(QPainter::CompositionMode_Source);
      // painter.fillRect( this-&gt;rect(), Qt::transparent );
      painter.setCompositionMode(QPainter::CompositionMode_Clear);
      painter.eraseRect( this-&gt;rect() );
      painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
  
      ...
  }
  </code></pre>
  
  <p>EDIT:
  Just noticed, using CompositionMode Source instead of SourceOver for my semi-transparent painting (gradient seen in first image) also causes them to be a red-to-black-gradient instead of red-to-transparent.</p>
  
  <p>That means every transparency except the inital by <code>WA_TranslucentBackground</code> or <code>WA_NoSystemBackground</code> isn't working.</p>