title: How to make Qt widgets fade in or fade out?
body: <p>I am trying to fade in and fade out a <code>QLabel</code> or for that matter any <code>QWidget</code> subclass. I have tried with <code>QGraphicsEffect</code>, but unfortunately it works well only on Windows and not on Mac. </p>
  
  <p>The only other solution which can work on both Mac &amp; Windows seems to be having my own custom <code>paintEvent</code> where I set the opacity of <code>QPainter</code> and also define a <code>Q_PROPERTY</code> for "opacity" in my derived <code>QLabel</code> and change the opacity through <code>QPropertyAnimation</code>. </p>
  
  <p>I am pasting below the relevant code snippet for your reference. I still see an issue here - reusing the <code>QLabel::paintEvent</code> doesn't seem to be working, it works only if I do a complete custom painting using the <code>QPainter</code>, but that doesn't seem to be an easy way and if I need to do that for every <code>QWidget</code> subclass I want to fade out, that's a nightmare. Please clarify if I am doing any obvious mistakes here.</p>
  
  <pre><code>Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
  
  void MyLabel::setOpacity(qreal value) {
      m_Opacity = value;
      repaint();
  }
  
  void MyLabel::paintEvent((QPaintEvent *pe) {
      QPainter p;
      p.begin(this);
      p.setOpacity();
      QLabel::paintEvent(pe);
      p.end();
  }
  
  void MyLabel::startFadeOutAnimation() {
      QPropertyAnimation *anim = new QPropertyAnimation(this, "opacity");
      anim-&gt;setDuration(800);
      anim-&gt;setStartValue(1.0);
      anim-&gt;setEndValue(0.0);
      anim-&gt;setEasingCurve(QEasingCurve::OutQuad);
      anim-&gt;start(QAbstractAnimation::DeleteWhenStopped);
  }
  </code></pre>