tags:

views:

59

answers:

3

Im using Qt framework , and i looking for the best method to show the user im processing something
how in Qt i can:
put the main window in the background and pop up window to the foreground with for example " processing " massage
until its done processing the " processing " window will close and the main window returns to the foreground .

+1  A: 

You can try that:

  • In the function that call the pop-up just hide the main window once the process pop-up displayed.
  • Connect the end processing signal to the main window slot Show(). If you have not predefined signal for that, create one and emit it.

    emit NameOfSignal;

Hope that helps

Edit:

For disabling the main window use setDisabled instead of hide and setEnabled instead of show.

Patrice Bernassola
i dont what to hide it , i want to make it disabled in the background (not hide more like idil)
See my edit in my answer
Patrice Bernassola
A: 

You can give your "Processing"-window the Qt::WindowStaysOnTopHint to make it stay on top of your disabled main window.

If it's not to fancy for you, you can blur your main window using QGraphicsBlurEffect while the processing window is on top. That way the user gets the impression of the main window to be not accessable until your processing is done.

Exa
+2  A: 

Use QProgressDialog. It is designed for that kind of use. You can use the QProgressDialog as a modal dialog thus preventing any user interaction to your main window. QProgressDialog also gives you an easy way to present the progress of your processing and an optional pushbutton to abort processing.

Edit:

QProgressBar can be used in two states: progressing in steps or just showing busy state.

QProgressDialog's progress bar cannot be used showing busy state because that would require setting QProgressDialog's min and max values to 0, which immediately closes the progress dialog. However, you can give the QProgressDialog a new progress bar using setBar()-function. Then you can set this progress bar's min, max and value to 0 and then getting the busy look.

QProgressDialog progressDialog("Processing...", "Abort", 0, INT_MAX, this);

QProgressBar* bar = new QProgressBar(&progressDialog);
bar->setRange(0, 0);
bar->setValue(0);
progress.setBar(bar);

progressDialog.setMinimumWidth(350);
progressDialog.setMinimumDuration(1000);
progressDialog.setWindowModality(Qt::WindowModal);
progressDialog.setValue(0);


// Do your time consuming processing here, but remember to change 
// the progress dialog's value a few times per second. 
// That will keep the busy indicator moving.
progressDialog.setValue(progressDialog.value() + 1);

// And check if the user has cancelled the processing
if (progressDialog.wasCanceled())
    break or return or whatever necessary


// When your processing is done, close the dialog.
progressDialog.close();
Roku
If you give the main window as the parent of the progress dialog and the progress dialog is modal, then the progress dialog should always stay on top of the main window as well.
Caleb Huitt - cjhuitt
this is great but is there any way to replace the progress bar with animated gif ?
I don't know how to easily replace the progress bar with gif, but I updated my answer to show how to use the QProgressDialog to show busy state instead of percentage of processing steps
Roku