Tutorial :Trouble with progressbar in QT



Question:

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();  


Solution:1

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();  


Solution:2

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-project.org/browse/QTBUG-10984


Solution:3

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. ;)


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »