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. [Another Question2] How to hide a label with fade/opacity levels?
QtWS25 Last Chance

[Another Question2] How to hide a label with fade/opacity levels?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 9.2k Views
  • 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.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    @label->hide();@
    Will hide a label immediately.. But i would like to hide label with an effect.. So it looks nicer...
    So is there any way i can hide a label with fade/opacity levels?

    What i mean is.. Not hide immediately the label.. But lower the opacity of the text, and lower, and lower until it goes to 0 ( when you can't see it basically ) and then hide it.. So is there any way of doing that?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      I guess you could use tricks to do that, yes, but I think you might be better off using a QGraphicsView or QML based UI for that sort of thing.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        srikanth_trulyit
        wrote on last edited by
        #3

        Implement a method say animatedHide() and run a simple QPropertyAnimation. The target property can be windowOpacity(i haven't checked it though). If that is not working, just create a qproperty like
        @
        Q_PROPERTY(qreal fade READ fade WRITE setFade)
        @

        and change the opacity from setFade and return the opacity in fade.

        Another approach which should be quite straight forward is to set a QGraphicsOpacityEffect on the label, this has nothing to do with GV, but can be applied on any QWidget also. Animate it using QPropertyAnimation on "opacity" property of QGraphicsOpacityEffect. See the concerned doc for more info.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Leon
          wrote on last edited by
          #4

          I don't know how to set a QGraphicsOpacityEffect on the label.. I read the doc but i can't understand how am i suppose to do it at the label.

          P.S QPropertyAnimation with target property to windowOpacity doesn't do anything.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            srikanth_trulyit
            wrote on last edited by
            #5

            You can set any graphics effect on any widget

            @
            QGraphicsOpacityEffect* opacityEffect = new QGraphicsOpacityEffect(this); // make sure to create using new, since effect has to be alive as long as the target widget is using it.
            opacityEffect->setValue(1); // initially widget should be visible
            myLabel->setGraphicsEffect(opacityEffect)
            QPropertyAnimation* anim = new QPropertyAnimation(this);
            anim->setTargetObject(opacityEffect);
            anim->setPropertyName("opacity");
            anim->setDuration(500);
            anim->setStartValue(opacityEffect->opacity());
            anim->setEndValue(0);
            anim->setEasingCurve(QEasingCurve::OutQuad);
            anim->start(QAbstractAnimation::DeleteWhenStopped);
            @

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Leon
              wrote on last edited by
              #6

              Ok instead of setValue(1) the correct one is setOpacity(1.0);
              The duration was to low so i changed it to 4000..
              And it works! Thanks again ;)

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Leon
                wrote on last edited by
                #7

                Is there anyway i can do this to more than one widget in the same time?

                @QGraphicsOpacityEffect* opacityEffect = new QGraphicsOpacityEffect(this);
                opacityEffect->setOpacity(1.0);
                ui->label->setGraphicsEffect(opacityEffect);
                QPropertyAnimation* anim = new QPropertyAnimation(this);
                anim->setTargetObject(opacityEffect);
                anim->setPropertyName("opacity");
                anim->setDuration(500);
                anim->setStartValue(opacityEffect->opacity());
                anim->setEndValue(0);
                anim->setEasingCurve(QEasingCurve::OutQuad);
                anim->start(QAbstractAnimation::DeleteWhenStopped);@

                Or should i just do the same thing for all widgets?

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #8

                  If I remember "correctly":http://labs.qt.nokia.com/2011/05/12/qt-modules-maturity-level-the-list/, graphics effects are considered deprecated. So if you are looking for a long-lasting solution you might look out for another approach.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    Leon
                    wrote on last edited by
                    #9

                    You know, i can hide 2 widgets like this

                    @QGraphicsOpacityEffect* opacityEffect = new QGraphicsOpacityEffect(this);
                    opacityEffect->setOpacity(1.0);
                    ui->label->setGraphicsEffect(opacityEffect);
                    QPropertyAnimation* anim = new QPropertyAnimation(this);
                    anim->setTargetObject(opacityEffect);
                    anim->setPropertyName("opacity");
                    anim->setDuration(500);
                    anim->setStartValue(opacityEffect->opacity());
                    anim->setEndValue(0);
                    anim->setEasingCurve(QEasingCurve::OutQuad);
                    anim->start(QAbstractAnimation::DeleteWhenStopped);

                     QGraphicsOpacityEffect* opacityEffect2 = new QGraphicsOpacityEffect(this);
                     opacityEffect2->setOpacity(1.0);
                     ui->label_2->setGraphicsEffect(opacityEffect2);
                     QPropertyAnimation* anim2 = new QPropertyAnimation(this);
                     anim2->setTargetObject(opacityEffect2);
                     anim2->setPropertyName("opacity");
                     anim2->setDuration(500);
                     anim2->setStartValue(opacityEffect2->opacity());
                     anim2->setEndValue(0);
                     anim2->setEasingCurve(QEasingCurve::OutQuad);
                     anim2->start(QAbstractAnimation::DeleteWhenStopped);@
                    

                    But i just want to know if there is way to do that in many widgets without the need to have the same code for every one.

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      Leon
                      wrote on last edited by
                      #10

                      Anyway ok i have done it one by one..
                      But is there any fade effect for a textedit?
                      Because it returns me this when i do the opacity effect to a textedit:

                      @QPainter::begin: A paint device can only be painted by one painter at a time.
                      QPainter::translate: Painter not active
                      QPainter::worldTransform: Painter not active
                      QPainter::setWorldTransform: Painter not active
                      QPainter::setWorldTransform: Painter not active@

                      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