Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Hide QGroupBox with QGraphicsOpacityEffect

Hide QGroupBox with QGraphicsOpacityEffect

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 807 Views 1 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!!

    I am trying to hide a QGroupBox with a QGraphicsOpacityEffect. I have this code:

    void class::showStretchingElements() {
        if (m_bShowStretchingElements) {
            QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
            ui->groupObjects->setGraphicsEffect(eff);
            QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
            a->setDuration(750);
            a->setStartValue(1);
            a->setEndValue(0);
            a->setEasingCurve(QEasingCurve::OutBack);
            a->start(QPropertyAnimation::DeleteWhenStopped);
            connect(a, &QPropertyAnimation::finished,this, &cameraDialog::endAnimation);
        }
        else {
            QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
            ui->groupObjects->setGraphicsEffect(eff);
            QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
            a->setDuration(750);
            a->setStartValue(0);
            a->setEndValue(1);
            a->setEasingCurve(QEasingCurve::OutBack);
            a->start(QPropertyAnimation::DeleteWhenStopped);
            connect(a, &QPropertyAnimation::finished,this, &cameraDialog::endAnimation);
        }
    }
    
    void class::endAnimation() {
        if (m_bShowStretchingElements) {
            ui->groupObjects->setHidden(true);
            m_bShowStretchingElements = false;
        } else {
            ui->groupObjects->setHidden(false);
            m_bShowStretchingElements = true;
        }
    }
    

    When I try to hide the QGroupBox, it works fine, but, when I try to show again, it shows it but without the animation. What's wrong here?

    Thank you very much!

    Pl45m4P 1 Reply Last reply
    0
    • ivanicyI ivanicy

      Hello!!

      I am trying to hide a QGroupBox with a QGraphicsOpacityEffect. I have this code:

      void class::showStretchingElements() {
          if (m_bShowStretchingElements) {
              QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
              ui->groupObjects->setGraphicsEffect(eff);
              QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
              a->setDuration(750);
              a->setStartValue(1);
              a->setEndValue(0);
              a->setEasingCurve(QEasingCurve::OutBack);
              a->start(QPropertyAnimation::DeleteWhenStopped);
              connect(a, &QPropertyAnimation::finished,this, &cameraDialog::endAnimation);
          }
          else {
              QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
              ui->groupObjects->setGraphicsEffect(eff);
              QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
              a->setDuration(750);
              a->setStartValue(0);
              a->setEndValue(1);
              a->setEasingCurve(QEasingCurve::OutBack);
              a->start(QPropertyAnimation::DeleteWhenStopped);
              connect(a, &QPropertyAnimation::finished,this, &cameraDialog::endAnimation);
          }
      }
      
      void class::endAnimation() {
          if (m_bShowStretchingElements) {
              ui->groupObjects->setHidden(true);
              m_bShowStretchingElements = false;
          } else {
              ui->groupObjects->setHidden(false);
              m_bShowStretchingElements = true;
          }
      }
      

      When I try to hide the QGroupBox, it works fine, but, when I try to show again, it shows it but without the animation. What's wrong here?

      Thank you very much!

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @ivanicy

      Try

      a->setEasingCurve(QEasingCurve::InBack);
      

      instead of QEasingCurve::OutBack in your fade-In (show) function. You are using a (cubic) function to set the opacity during your animation time. Currently you have the same function for hiding and showing the QGroupBox. This is why you probably see some weird behavior.

      You can check these functions here: https://doc.qt.io/qt-5/qeasingcurve.html#Type-enum

      Or is your fade-in animation not starting at all? Do you reach your endAnimation - slot twice (after fade-Out and fade-In)?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      ivanicyI 1 Reply Last reply
      1
      • Pl45m4P Pl45m4

        @ivanicy

        Try

        a->setEasingCurve(QEasingCurve::InBack);
        

        instead of QEasingCurve::OutBack in your fade-In (show) function. You are using a (cubic) function to set the opacity during your animation time. Currently you have the same function for hiding and showing the QGroupBox. This is why you probably see some weird behavior.

        You can check these functions here: https://doc.qt.io/qt-5/qeasingcurve.html#Type-enum

        Or is your fade-in animation not starting at all? Do you reach your endAnimation - slot twice (after fade-Out and fade-In)?

        ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by ivanicy
        #3

        @Pl45m4 Yes, I reach it twice. m_bShowStretchingElements is a boolean that changes and make the condition. I'm still having the same problem. When I call the show function for showing the QGroupBox, it appears suddenly, without any animation.

        Pl45m4P 1 Reply Last reply
        0
        • ivanicyI ivanicy

          @Pl45m4 Yes, I reach it twice. m_bShowStretchingElements is a boolean that changes and make the condition. I'm still having the same problem. When I call the show function for showing the QGroupBox, it appears suddenly, without any animation.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @ivanicy

          Your code doesn't look wrong. Move the connect statement some lines upwards (right after you init a) and try again.

          This works for me (the only difference is, that I don't hide the widget after fading out. I also have a private QGraphicsOpacityEffect - member)

          MainWindow::MainWindow(QWidget *parent):
              QMainWindow(parent),
              ui(new Ui::MainWindow),
              m_eff(new QGraphicsOpacityEffect(this))
          {
              m_eff->setOpacity(1);
              ui->widget->setGraphicsEffect(m_eff);
          }
          
          
          void MainWindow::fadeIn()
          {
              QPropertyAnimation *animation = new QPropertyAnimation(m_eff, "opacity");
              animation->setDuration(1000);
              animation->setStartValue(0);
              animation->setEndValue(1);
              animation->setEasingCurve(QEasingCurve::InQuart);
              animation->start(QPropertyAnimation::DeleteWhenStopped);
          }
          
          void MainWindow::fadeOut()
          {
              QPropertyAnimation *animation = new QPropertyAnimation(m_eff, "opacity");
              animation->setDuration(1000);
              animation->setStartValue(1);
              animation->setEndValue(0);
              animation->setEasingCurve(QEasingCurve::OutQuart);
              animation->start(QPropertyAnimation::DeleteWhenStopped);
          }
          
          

          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          ivanicyI 1 Reply Last reply
          1
          • Pl45m4P Pl45m4

            @ivanicy

            Your code doesn't look wrong. Move the connect statement some lines upwards (right after you init a) and try again.

            This works for me (the only difference is, that I don't hide the widget after fading out. I also have a private QGraphicsOpacityEffect - member)

            MainWindow::MainWindow(QWidget *parent):
                QMainWindow(parent),
                ui(new Ui::MainWindow),
                m_eff(new QGraphicsOpacityEffect(this))
            {
                m_eff->setOpacity(1);
                ui->widget->setGraphicsEffect(m_eff);
            }
            
            
            void MainWindow::fadeIn()
            {
                QPropertyAnimation *animation = new QPropertyAnimation(m_eff, "opacity");
                animation->setDuration(1000);
                animation->setStartValue(0);
                animation->setEndValue(1);
                animation->setEasingCurve(QEasingCurve::InQuart);
                animation->start(QPropertyAnimation::DeleteWhenStopped);
            }
            
            void MainWindow::fadeOut()
            {
                QPropertyAnimation *animation = new QPropertyAnimation(m_eff, "opacity");
                animation->setDuration(1000);
                animation->setStartValue(1);
                animation->setEndValue(0);
                animation->setEasingCurve(QEasingCurve::OutQuart);
                animation->start(QPropertyAnimation::DeleteWhenStopped);
            }
            
            
            ivanicyI Offline
            ivanicyI Offline
            ivanicy
            wrote on last edited by
            #5

            @Pl45m4 I could solve it with your help! You were right, I don't hide the widget and it works! I only have to add a QGroupBox.setEnabled(false) and its done!.

            Pl45m4P 1 Reply Last reply
            2
            • ivanicyI ivanicy

              @Pl45m4 I could solve it with your help! You were right, I don't hide the widget and it works! I only have to add a QGroupBox.setEnabled(false) and its done!.

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @ivanicy

              Yes, after rethinking, it makes sense. :-)
              When you fade-Out your GroupBox and hide it afterwards, the GroupBox is still hidden, when you start the animation. After animation time, you set hidden (false) and the GroupBox just pops up. (because your fade-In animation process is already done)


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0

              • Login

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