Qt Code:
  1. void MainWindow::dissolve( QWidget * pFadeOut, QWidget * pFadeIn )
  2. {
  3. QByteArray opacityProp( QString( "windowOpacity" ).toLatin1() );
  4. QPropertyAnimation * pFadeOutAnimation = new QPropertyAnimation( pFadeOut, opacityProp );
  5. QPropertyAnimation * pFadeInAnimation = new QPropertyAnimation( pFadeIn, opacityProp );
  6.  
  7. int duration = 3000;
  8. pFadeOutAnimation->setDuration( duration );
  9. pDafeOutAnimation->setStartValue( 1.0 );
  10. pFadeOutAnimation->setEndValue( 0.0 );
  11.  
  12. // Hide the fade out widget when the animation has stopped
  13. connect( pFadeOutAnimation, &QPropertyAnimation::finished, pFadeOut, &QWidget::hide );
  14.  
  15. pFadeInAnimation->setDuration( duration );
  16. pFadeInAnimation->setStartValue( 0.0 );
  17. pFadeInAnimation->setEndValue( 1.0 );
  18.  
  19. // Ensure the fade in widget is showing, but make it invisible by setting opacity to 0
  20. if ( !pFadeIn->isVisible() )
  21. {
  22. pFadeIn->setWindowOpacity( 0.0 );
  23. pFadeIn->show();
  24. }
  25.  
  26. pFadeOutAnimation->start( QAbstractAnimation::DeleteWhenStopped );
  27. pFadeInAnimation->start( QAbstractAnimation::DeleteWhenStopped );
  28. }
To copy to clipboard, switch view to plain text mode 

Not tested, so may require some edits.