0

I have a task were I need to execute a sequence of PropertyAnimations. One of the animations is changing the visibility of a QWidget. When I try to hide it, it works perfectly fine:

QPropertyAnimation *pAnim = new QPropertyAnimation(pWidget, "visible");
pAnim->setStartValue(true);
pAnim->setEndValue(false);
pAnim->start(QAbstractAnimation::DeleteWhenStopped);

But when I try it the other way around, nothing happens:

QPropertyAnimation *pAnim = new QPropertyAnimation(pWidget, "visible");
pAnim->setStartValue(false);
pAnim->setEndValue(true);
pAnim->start(QAbstractAnimation::DeleteWhenStopped);

Am I doing something wrong? Or might this be a bug in Qt? I am using Qt 5.6.1 if that helps.

1 Answers1

0

Here's the answer I got from the Qt support:

bool is not interpolatable type which results in invalid QVariant, which just happens to convert to false, so boolean properties can never be set to true by default.[..]

It is probably better to make your own QAbstractAnimation subclass which just sets the property to new value. However, you can of course define your interpolation function for bool for it. For example:

static QVariant bool_interpolator(const bool& from, const bool& to, qreal progress) { return progress < 0.5 ? from : to; } ... qRegisterAnimationInterpolator(bool_interpolator);

I tested the solution with interpolator and it worked exactly as I needed it.