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