You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, January 18th 2012, 11:08am

GUI animation help required

Hi,

I am new to QT..just started learning the same. I have good understanding of C++.

Just not clear on GUI programming when done with QT.

I have one Dialog where I need to move few widgets based on some calculation. My calculation runs in while loop and moving of widgets is done with the help of timer. Timer is used because I want to show some animated effect while moving widget...

But, this does not work...code snippet is given below..The reason may be while loop inside also runs while timer is running...that causes timer to restart everytime with new widget to move...


Dialog::Dialog(QWidget*parent) :QDialog(parent)
{


QPushButton*push=newQPushButton(this);

connect(push,SIGNAL(clicked()),this,SLOT(moveWidgets()));
timer=newQTimer(this);

....some code for initializing array of widgets and their positions on dialog

setWindowTitle(tr("This dialog title"));

}
void Dialog::moveWidgets()
{
while(widget!=null)

{

Widget.doCalculationForitsNewPosition();

move(widget);

widget = getNextWidget();

}

}

void Dialog::move(widget)

{

timer1->start(100);

}

//this is timer update function
voidDialog::updateTimer()

{

//imagine code here which will move widget by one step.

if(widget is moved to final position)

{

timer->stop();

}

}





You can see that move(widget) function starts timer for animating movement of widget. But, move(widget) itself is being run inside while loop and that while loop restarts the timer....hence only last widget moves...:(

Can anyone suggest me how to use QThread or some other technique to make sure that only after timer is stopped, while loop continues to next widget...?

Thanks

2

Wednesday, January 18th 2012, 12:33pm

why arent you using qt animation? http://developer.qt.nokia.com/doc/qt-4.8…n-overview.html

if yuo insist on using your method, you need to think about why you have not connected the timer's timeout signal to anything.

I wont even ask why it seems you are not using any layouts...
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Wednesday, January 18th 2012, 12:47pm

Thanks Amleto,

I will look at suggestions given by you. I want random positions of widgets on form, hence not used any layout.

Sorry for not typing complete code. It is dirty at the moment...(lot of things commented).

4

Wednesday, January 18th 2012, 1:42pm

missed following line in code snippet
connect(timer,SIGNAL(timeout()),this,SLOT(updateTimer()));

when timeout is signaled, it calls updateTimer which will perfom some animation. But, move(widget) itself is being run inside while loop and that while loop restarts the timer....hence only last widget moves.

5

Wednesday, January 18th 2012, 4:28pm

you could use two timers... one to start the loop, and one to wait between each loop iteration
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

6

Wednesday, January 18th 2012, 5:58pm

Thanks Amleto,

Two timer solution worked.

I had to change my while loop logic...but finally that worked.

Thanks a ton.

Used tags

GUI, qthread