I want to animate error messages inside the status bar of my application.
I use a QLabel for the statusbar.

On status bar change i do the following:

Qt Code:
  1. void sectiona::statusBarChanged(const QString& text, bool message)
  2. {
  3. QLabel* b=m_gui->m_textOut;
  4. QString newtext;
  5. oldStatusBarText=b->text();
  6. if(message==false)
  7. {
  8. b->setText(text);
  9. return;
  10. }else //animated message
  11. {
  12. newtext=text;
  13. newtext=newtext.prepend("<font color=\"red\"><b>").append("</b></font>");
  14. b->setText(newtext);
  15. QGraphicsOpacityEffect* effect=new QGraphicsOpacityEffect(b);
  16. b->setGraphicsEffect(effect);
  17. QPropertyAnimation* animation=new QPropertyAnimation(effect,"opacity");
  18. effect->setOpacity(0.0);
  19. animation->setDuration(3000);
  20. animation->setKeyValueAt(0.0,1.0);
  21. animation->setKeyValueAt(0.9,1.0);
  22. animation->setKeyValueAt(1.0,0.0);
  23. animation->setEasingCurve(QEasingCurve::InOutCubic);
  24. connect(animation,SIGNAL(finished()),this,SLOT(statusBarAnimationFinished()));
  25. animation->start(QAbstractAnimation::DeleteWhenStopped);
  26. };
  27. }
To copy to clipboard, switch view to plain text mode 

if the new status bar is a temporary message I animate the fadeout for 3seconds and then on the finish of the animation I restore the permanent status bar text:

Qt Code:
  1. void sectiona::statusBarAnimationFinished()
  2. {
  3. QLabel* b=m_gui->m_textOut;
  4. QGraphicsOpacityEffect* effect=new QGraphicsOpacityEffect(b);
  5. effect->setOpacity(0.0);
  6. qDebug()<<effect->opacity();
  7. b->setText(oldStatusBarText);
  8. qDebug()<<effect->opacity();
  9. b->setGraphicsEffect(effect);
  10. qDebug()<<effect->opacity();
  11. b->setText(oldStatusBarText);
  12. qDebug()<<effect->opacity();
  13. effect->setOpacity(1.0);
  14. qDebug()<<effect->opacity();
  15. }
To copy to clipboard, switch view to plain text mode 

It works fine except a minor detail. The qDebug statements return:
Qt Code:
  1. 0
  2. 0
  3. 0
  4. 0
  5. 1
To copy to clipboard, switch view to plain text mode 
, so the opacity changes only on the final statement, <b>BUT</b> the previous text blinks for a frame before setting the oldStatusBarText
I want to smoothly disappear the message, and the just update the QLabel with the previous text.
Any ideas?