PDA

View Full Version : QSequentialAnimationGroup don't seems to start all animations



NullPointer
11th September 2011, 22:43
Hi all,

I'm trying to animate my QMainWindow subclasses every time them get showed.
For that I wrote the following:

void Loader_mainWindow::showEvent(QShowEvent * ){
ui->centralWidget->hide(); //hide everything inside to improve speed
QPropertyAnimation * pa=new QPropertyAnimation();
pa->setDuration(1000);
pa->setStartValue(QRect(0,0,0,0));
pa->setEndValue(QRect(100,100,500,350));
pa->setTargetObject(this);
pa->setPropertyName("geometry");
QPropertyAnimation * pb0=new QPropertyAnimation(ui->centralWidget, "visible"); //this animation shows the centralWidget
pb0->setStartValue(false);
pb0->setEndValue(true);
pb0->setDuration(10);
QPropertyAnimation *pb=new QPropertyAnimation(); //and this one gives me a fade in effect
pb->setDuration(1000);
pb->setStartValue(0.0f);
pb->setEndValue(1.0f);
pb->setTargetObject(ui->centralWidget);
pb->setPropertyName("windowOpacity");
QSequentialAnimationGroup *ag=new QSequentialAnimationGroup();
ag->addAnimation(pa);
ag->addAnimation(pb0);
ag->addAnimation(pb);
ag->setLoopCount(2);
ag->start();
}


Happens that only the first animation seems to get executed, the centralWidget is not showed and there is no fade in for the controls...
This code doesn't give me any error code (all properties are ok). And if I remove de pb0 animation, the fade doesn't happen too.

What is wrong??

Thanks in advance.

llev
12th September 2011, 02:34
IIRC windowOpacity works for windows only, i.e. widgets with no parent widget.
Your centralWidget is not a window. Correct?
If so use QGraphicsOpacityEffect instead.
As to your "pb0" which should animate bool value.
I'm looking at QVariantAnimation class (which is the ancestor of QPropertyAnimation class) documentation and I'm not seeing bool in the list of supported property types.
So I'm not sure bool property can be animated.
Maybe opacity animation is enough (despite of "speed")? :)

NullPointer
12th September 2011, 03:08
Thanks for the tips :D

I was hiding the central widget to avoid it to be resizing every widget inside... I have a layout with many controls, and this is cpu-intense, breaking the effect :S
I'll try animating the QGraphicsOpacityEffect (http://doc.qt.nokia.com/latest/qgraphicsopacityeffect.html) ;)
You are right, there is no way to "animate" a bool... I'll try that with the signal of animation changed... a Direct Connection should fix it :D

thanks a lot