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 .
views:
59answers:
3Qt: how can i put my main window in the background while im processing with window in forground?
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.
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.
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();