views:

654

answers:

3

Hi..

i m facing problem in giving animation to progressbar in QT.

where is the mistake in the following code, i am getting continues progress bar, but its not animating

  QApplication a(argc, argv);

QProgressDialog *dialog = new QProgressDialog();


QProgressBar *pbar = new QProgressBar(dialog);

pbar->setMinimum(0);
pbar->setMaximum(0);
pbar->setTextVisible(false);

QDesktopWidget *desktop = QApplication::desktop();
QRect rect = desktop->geometry();

pbar->setGeometry(rect.left(),rect.top(),rect.right(),rect.bottom()-300);

pbar->show();


dialog->setBar(pbar);

dialog->showMaximized(); 
dialog->exec();   
return a.exec();
+6  A: 

I tried this code on WinXP with Qt 4.5.3 and it works as expected. I cannot give you a solution but i have a suggestion: You don't need to set a QProgressBar to QProgressDialog, it already has its own.

Removing the code for QProgressBar, the code below does the same thing with your original code on my machine.

QApplication a(argc, argv);

QProgressDialog *dialog = new QProgressDialog();

dialog->setMinimum(0);
dialog->setMaximum(0);

dialog->showMaximized(); 
dialog->exec();   
return a.exec();
erelender
Hey i got it..Thanks for ur suggestionthe thing is.. ur code is also behaving like the code above mine..in my emulator i m getting progress bar, with the zigzag style.. i.e while blue..but its static.. i mean its not moving..emulator behaviour is like that only or what?
Shadow
Hmm, i have never worked with symbian but that seems like somethig an emulator can do. Can you try deploying it on an actual symbian machine to try?
erelender
ya.. ill try in mobile and tell u :)Thanks
Shadow
Hey.. i tried in mobile.its not animating.. just static progress bar is showing
Shadow
A: 

Dudes, what exactly do you think that a progress bar does? It is supposed to show the user that an activity is ongoing and also what is the current progress state.

Your code

QProgressDialog *dialog = new QProgressDialog();

dialog->setMinimum(0);

dialog->setMaximum(0);

would indicate that a certain operation will start with status 0 and will end when the status (or current value) reaches value ... 0. And you want some animation going with that?

See an example at http://doc.trolltech.com/4.6/qprogressdialog.html#details

Basically you should create a progress dialog with a min and a max value

QProgressDialog *dialog = new QProgressDialog();

dialog->setMinimum(0);

dialog->setMaximum(100);

Then have the actual progress value updated (e.g. on a timer which triggers the perform slot) in order to have it represented in the progress bar:

void Operation::perform()
{
     dialog->setValue(steps);
     //... perform one percent of the operation
     steps++;
     if (steps > dialog->maximum())
         t->stop();
}

A series of updates, with progressively increasing progress value, will create the animation effect you want.

Obviously tagging this with Symbian is pure wrong, this is not at all Symbian specific. Nor is it Qt 4.x specific, hell ... it's not even Qt specific, it's basically a logic issue. ;)

Lucian
Actually these days progress bars also can be used to show that the application is still doing something but the progress can't be estimated. This is animated and called marquee mode ( or knightrider mode). Setting the min and max to 0 does this in Qt.
Thirler
Interesting. Thanks for the tip. I see something like that on Windows but it is not documented behaviour.
Lucian
A: 

If you're using the Windows Vista theme (QWindowsVistaStyle) then there's a bug that means indeterminate progress bars don't animate. I've written up the bug here, complete with simple patch: http://bugreports.qt.nokia.com/browse/QTBUG-10984

jlarcombe
@jlarcombe, i found the solution for the problem.may i know which version of Qt are you using?, Qt say issue is fixed in Qt 4.6.2
Shadow
This was going wrong for me in the 4.7 tech preview. Perhaps it's a different problem to what you're seeing.
jlarcombe