Custom QProgressDialog
-
Hi
I wanted to build a custom progress dialog for my project so I built a dialog with a progressBar in the ui and two public functions:
void setProgressBarValue(int value)
{
ui->progressBar->setValue(value);
}void setProgressBarRange(int min, int max)
{
ui->progressBar->setRange(min, max);
}And in my project:
myProgressDialog *dialog = new myProgressDialog;
dialog.setProgressBarRange(0,100);
dialog.show();for (int i=0; i<=100; ++i)
{
dialog.setProgressBarValue(i);
}And when I run it it shows the dialog but inside the dialog is black until it reaches 100
I know I'm doing everything wrong so can someone tell me how to do it? -
Hello,
Your code doesn't allow for the events to be processed between the calls todialog.setProgressBarValue(i);
, this is why the first paint event you'll get processed is after the loop finishes. You could manually request events to be processed in the loop by using QCoreApplication::processEvents.Kind regards.
-
Hi,
Thank you so much. I did it.