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?


  • Qt Champions 2016

    Hello,
    Your code doesn't allow for the events to be processed between the calls to dialog.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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.