Animation doesn't work outside constructor
-
Hi, I'm using Qt creator 2.4.1 (4.8.0 library) under linux. I successfully developed a Widget based in a QDialog in which a fancy animation (Qframe geometry property) runs properly. Then the problem came up when I included this widget into another one. The animation no longer works. I found out that if I include it inside the constructor of the second widget, the animation works again, but when I executed outside, doesn't. I tried creating the Dialog widget as a pointer, as a local variable, as a global variable, as a private member in the second class, but nothing works. No mater if I initialise the class pointer in the constructor of the second widget, as long as I don't executed in that place, the animation doesn't work.
Could anyone offer me a helping hand.
Many thanks. -
Did you add your animated widget to a layout in the parent widget? If so this will certainly stop your geometry animation from working, since the layout will try to manage the widget geometry. If this is not the case you should post a few lines of code that can help us analyze your problem.
-
Part of the source code in configuration dialog "MyClass" constructor is
@
MyDialog::MyDialog( QWidget *parent) : QDialog(parent, Qt::FramelessWindowHint ),
ui(new Ui::MyDialog)
{
ui->setupUi(this);
QPropertyAnimation *animation = new QPropertyAnimation( ui->pushButton, "geometry", this );
animation->setDuration(500);
animation->setEasingCurve( QEasingCurve::InOutQuad );QStateMachine *stateMachine = new QStateMachine(this);
QState *state1 = new QState(stateMachine);
QState *state2 = new QState(stateMachine);state1->assignProperty( ui->pushButton, "geometry", QRect( 60, 125, 680, 220));
state2->assignProperty( ui->pushButton, "geometry", QRect( 60, 50, 680, 220 ));QSignalTransition *goState2Transition = new QSignalTransition(ui->nextButton, SIGNAL(clicked()), state1);
QSignalTransition *goState1Transition = new QSignalTransition(ui->backButton, SIGNAL(clicked()), state2);
goState2Transition->setTargetState( state2 );
goState2Transition->addAnimation( animation );
goState1Transition->setTargetState( state1 );
goState1Transition->addAnimation( animation );
stateMachine->setInitialState( state1 );
stateMachine->start();
}@When I run the configuration dialog from other project, let's call it MainProject, as long as I included in the constructor of that other project, works fine. I tried to show MyDialog from a function inside my MainProject and the animation doesn't work.
-
Can you show code samples that illustrate the use of your class that breaks your animation and the use case that works?
-
The use is simple. When I call MyDialog from MainProject constructor, works
@MainProject::MainProject(QWidget parent = 0) : QDialog(parent)
{
ui->setupUi(this);..
MyDialog * myDialog= new MyDialog(this);
myDialog->exec();
..
..
}
@
now when I call from another function by copying exactly the same piece of code, doesn't work.
Now the funny thing I found out, is that if I delete the whole object files and make a clean an rebuild all, the animation works, but only the first time. After that, anytime I re-run the application, doesn’t work anymore.