Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Fading out a QLabel
Forum Updated to NodeBB v4.3 + New Features

Fading out a QLabel

Scheduled Pinned Locked Moved Mobile and Embedded
qlabelfade
13 Posts 3 Posters 7.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    McLion
    wrote on 5 Aug 2015, 08:47 last edited by McLion 8 May 2015, 08:48
    #1

    Hi

    While searching the web I found many hints on this. However, I don't get what I am doing wrong. My code compiles without error but crashes at runtime.

    void QTGUI_MainWindow::ShowAndFadeLivePauseInfo()
    {
    qDebug() << "Start of FadeOut .. turn on";
    
      QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(ui->lblLivePause);
      ui->lblLivePause->setGraphicsEffect(effect);
      QPropertyAnimation* animation = new QPropertyAnimation(effect, "opacity");
      animation->setDuration(LP_FADEOUT_DURATION);
      animation->setStartValue(1.0);
      animation->setEndValue(0.0);
      animation->setEasingCurve(QEasingCurve::OutQuad);
      connect(animation,SIGNAL(finished()),this,SLOT(FadeLivePauseInfoEnded()));
      animation->start(QAbstractAnimation::DeleteWhenStopped);
      ui->lblLivePause->show();
    }
    

    What did I miss?
    Thanks
    McL

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca
      wrote on 5 Aug 2015, 09:03 last edited by luca 8 May 2015, 09:04
      #2

      Hi, I made a FadingLabel to use where I need it.
      You can see my Class below, hope this helps.

      fadinglabel.h

      #ifndef FADINGLABEL_H
      #define FADINGLABEL_H
      #include <QLabel>
      #include <QGraphicsOpacityEffect>
      #include <QPropertyAnimation>
      #include <QEasingCurve>
      class FadingLabel : public QLabel
      {
      public:
          FadingLabel(QWidget *parent=0);
          void startFading(int num_fade=-1);
          ~FadingLabel();
          void setFadingOptions(int duration_msec, int interval_msec, QEasingCurve curve_type);
          void setDisabled();
      private:
          QGraphicsOpacityEffect *m_opacityEffect;
          QPropertyAnimation *m_opacityAnimation;
          int m_fadingTimer;
          void timerEvent(QTimerEvent *e);
          int m_durationMsec;
          int m_intervalMsec;
          QEasingCurve m_curveType;
          void fade();
          bool m_from0to1;
          int m_numFade;
          int m_executedFade;
      private slots:
          void fadingFinished();
      };
      #endif // FADINGLABEL_H
      

      fadinglabel.cpp

      #include "fadinglabel.h"
      #include <QTimerEvent>
      #include <QTimer>
      
      FadingLabel::FadingLabel(QWidget *parent) :
          QLabel(parent)
      {
          m_executedFade =0;
          m_opacityAnimation = new QPropertyAnimation(this);
          m_opacityEffect= new QGraphicsOpacityEffect(this);
          m_opacityEffect->setOpacity(0.2);
          this->setGraphicsEffect(m_opacityEffect);
          m_opacityAnimation->setTargetObject(m_opacityEffect);
          m_opacityAnimation->setPropertyName("opacity");
      
          m_from0to1 = true;
          connect(m_opacityAnimation, &QPropertyAnimation::finished, this, &FadingLabel::fadingFinished);
      }
      
      void FadingLabel::setFadingOptions(int duration_msec, int interval_msec, QEasingCurve curve_type)
      {
          m_durationMsec = duration_msec;
          m_intervalMsec = interval_msec;
          m_curveType = curve_type;
      
          m_opacityAnimation->setDuration(m_durationMsec);
          m_opacityAnimation->setEasingCurve(m_curveType);
      }
      
      void FadingLabel::setDisabled()
      {
          killTimer(m_fadingTimer);
          m_opacityAnimation->stop();
          m_opacityEffect->setOpacity(0.2);    
      }
      
      void FadingLabel::startFading(int num_fade)
      {
          m_numFade = num_fade;
          m_fadingTimer = startTimer(m_intervalMsec);
          m_from0to1 = true;
          fade();
      }
      
      FadingLabel::~FadingLabel()
      {
      
      }
      
      void FadingLabel::timerEvent(QTimerEvent *e)
      {
          if(e->timerId() == m_fadingTimer)
              fade();
      }
      
      void FadingLabel::fade()
      {
          if(m_from0to1)
          {
              m_opacityEffect->setOpacity(0);
              m_opacityAnimation->setStartValue(0);
              m_opacityAnimation->setEndValue(1.0);
              m_from0to1 = false;
          }
          else
          {
              m_opacityEffect->setOpacity(1.0);
              m_opacityAnimation->setStartValue(1.0);
              m_opacityAnimation->setEndValue(0);
              m_from0to1 = true;
          }
          m_opacityAnimation->start();
      }
      
      void FadingLabel::fadingFinished()
      {
          if(m_from0to1)
              fade();
          else
          {
              if(m_numFade!=-1)
              {
                  m_executedFade++;
                  if(m_executedFade>=m_numFade)
                  {
                      killTimer(m_fadingTimer);
                      m_executedFade=0;
                  }
              }
          }
      }
      

      Let me know.

      Luca

      1 Reply Last reply
      1
      • M Offline
        M Offline
        McLion
        wrote on 5 Aug 2015, 09:51 last edited by McLion 8 May 2015, 09:52
        #3

        Hi Luca,

        Thanks. I'll have a look at it and maybe implement it as a class with some modifications.
        However, looking at your code, you're doing about the same I do and I still do not understand why my code is not working as expected.

        Thanks
        McL

        L 1 Reply Last reply 5 Aug 2015, 10:17
        0
        • M McLion
          5 Aug 2015, 09:51

          Hi Luca,

          Thanks. I'll have a look at it and maybe implement it as a class with some modifications.
          However, looking at your code, you're doing about the same I do and I still do not understand why my code is not working as expected.

          Thanks
          McL

          L Offline
          L Offline
          luca
          wrote on 5 Aug 2015, 10:17 last edited by
          #4

          @McLion Hi, have you tried to remove "DeleteWhenStopped" ?
          I never used it and by default start() has "KeepWhenStopped".

          Just to try...

          M 1 Reply Last reply 5 Aug 2015, 11:29
          0
          • L luca
            5 Aug 2015, 10:17

            @McLion Hi, have you tried to remove "DeleteWhenStopped" ?
            I never used it and by default start() has "KeepWhenStopped".

            Just to try...

            M Offline
            M Offline
            McLion
            wrote on 5 Aug 2015, 11:29 last edited by
            #5

            @luca
            No joy ... thanks anyway.
            Somebody any other idea?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              McLion
              wrote on 5 Aug 2015, 11:42 last edited by
              #6

              I currently have set fixed transparency in designer by adding a styleSheet "background-color: rgba(160, 160, 160, 200)" to the label.
              Can I animate the a value of the styleSheet?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                McLion
                wrote on 7 Aug 2015, 08:27 last edited by
                #7

                .. bump ..
                Nobody any idea .. I'm still trying to get this going.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  McLion
                  wrote on 11 Aug 2015, 14:59 last edited by
                  #8

                  I'll bump it a gain ... really nobody any idea what I am doing wrong?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sneubert
                    wrote on 11 Aug 2015, 17:25 last edited by
                    #9

                    The code you show has no error. I made a minimal example with just a button and a label.

                    void MainWindow::on_pushButton_clicked()
                    {
                    
                        QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect();
                        ui->label->setGraphicsEffect(effect);
                        QPropertyAnimation *anim = new QPropertyAnimation(effect,"opacity");
                        anim->setDuration(1000);
                        anim->setStartValue(1.0);
                        anim->setEndValue(0.0);
                        anim->setEasingCurve(QEasingCurve::OutQuad);
                        connect(anim, &QPropertyAnimation::finished, [=]()
                        {
                            ui->label->setText("gone");
                        });
                    
                        anim->start(QAbstractAnimation::DeleteWhenStopped);
                    }
                    

                    The label fades out as expected. Your crash is bred in another place.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      McLion
                      wrote on 12 Aug 2015, 10:03 last edited by McLion 8 Dec 2015, 10:52
                      #10

                      Thanks for trying to help.
                      I added a new button and a label and tried with your code, except the connect that I changed to:
                      connect(anim, SIGNAL(finished()),this, SLOT(FadeLivePauseInfoEnded()));
                      because the compiler did not accept what you posted.

                      When I click the button Qt crashes exactly as before with this on the console:
                      (!) [ 691: 17.475] --> Caught signal 11 (at 0x24, invalid address) <--
                      (!!!) *** WARNING [still objects in 'Window Pool'] *** [object.c:241 in fusion_object_pool_destroy()]
                      -> ref context 0x20018000...
                      (!!!) *** WARNING [still objects in 'Layer Region Pool'] *** [object.c:241 in fusion_object_pool_destroy()]
                      (!!!) *** WARNING [still objects in 'Layer Context Pool'] *** [object.c:241 in fusion_object_pool_destroy()]
                      (!!!) *** WARNING [still objects in 'Surface Pool'] *** [object.c:241 in fusion_object_pool_destroy()]
                      (!) FUSION_PROPERTY_CEDE --> Input/output error
                      (!) Direct/Thread: Canceling 'Fusion Dispatch' (709)!

                      Any idea?

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        sneubert
                        wrote on 12 Aug 2015, 11:03 last edited by
                        #11

                        just clarify:
                        Did you add a new button and label to your exisiting project or did you create a new project with just a button and a label.
                        In first case debug your code and find the position which causes the sigsegv and we can further investigate whats going wrong. In second case list your arch, qt-version, compiler, etc. Maybe there“s a known bug.

                        Once again, the code you showed is correct and is not the cause of the sigsegv.

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          McLion
                          wrote on 12 Aug 2015, 11:26 last edited by McLion 8 Dec 2015, 11:26
                          #12

                          OK.
                          Just created a brand new project with only a button and a label, compiled for Windows only, and it works as supposed.
                          In my current working project I am developing on Windows for eLinux. If I run the code on my Windows devPC it does not crash, but also does not fade the label either. On my eLinux Target, the same code shows the widgets and crashes when I hit the button.

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            McLion
                            wrote on 12 Aug 2015, 12:02 last edited by
                            #13

                            Further debugging shows that it works in my project on Windows but not when I compile for eLinux.
                            Must be something that does not work with Qt 4.6.3 with DFB 1.4.3 and Fusion on eLinux.

                            1 Reply Last reply
                            0

                            3/13

                            5 Aug 2015, 09:51

                            10 unread
                            • Login

                            • Login or register to search.
                            3 out of 13
                            • First post
                              3/13
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved