{
QPropertyAnimation * pFadeOutAnimation = new QPropertyAnimation( pFadeOut, opacityProp );
QPropertyAnimation * pFadeInAnimation = new QPropertyAnimation( pFadeIn, opacityProp );
int duration = 3000;
pFadeOutAnimation->setDuration( duration );
pDafeOutAnimation->setStartValue( 1.0 );
pFadeOutAnimation->setEndValue( 0.0 );
// Hide the fade out widget when the animation has stopped
connect( pFadeOutAnimation, &QPropertyAnimation::finished, pFadeOut, &QWidget::hide );
pFadeInAnimation->setDuration( duration );
pFadeInAnimation->setStartValue( 0.0 );
pFadeInAnimation->setEndValue( 1.0 );
// Ensure the fade in widget is showing, but make it invisible by setting opacity to 0
if ( !pFadeIn->isVisible() )
{
pFadeIn->setWindowOpacity( 0.0 );
pFadeIn->show();
}
pFadeOutAnimation->start( QAbstractAnimation::DeleteWhenStopped );
pFadeInAnimation->start( QAbstractAnimation::DeleteWhenStopped );
}
void MainWindow::dissolve( QWidget * pFadeOut, QWidget * pFadeIn )
{
QByteArray opacityProp( QString( "windowOpacity" ).toLatin1() );
QPropertyAnimation * pFadeOutAnimation = new QPropertyAnimation( pFadeOut, opacityProp );
QPropertyAnimation * pFadeInAnimation = new QPropertyAnimation( pFadeIn, opacityProp );
int duration = 3000;
pFadeOutAnimation->setDuration( duration );
pDafeOutAnimation->setStartValue( 1.0 );
pFadeOutAnimation->setEndValue( 0.0 );
// Hide the fade out widget when the animation has stopped
connect( pFadeOutAnimation, &QPropertyAnimation::finished, pFadeOut, &QWidget::hide );
pFadeInAnimation->setDuration( duration );
pFadeInAnimation->setStartValue( 0.0 );
pFadeInAnimation->setEndValue( 1.0 );
// Ensure the fade in widget is showing, but make it invisible by setting opacity to 0
if ( !pFadeIn->isVisible() )
{
pFadeIn->setWindowOpacity( 0.0 );
pFadeIn->show();
}
pFadeOutAnimation->start( QAbstractAnimation::DeleteWhenStopped );
pFadeInAnimation->start( QAbstractAnimation::DeleteWhenStopped );
}
To copy to clipboard, switch view to plain text mode
Not tested, so may require some edits.
Bookmarks