Search code examples
qtfocusblockingqdialogqmessagebox

QMessageBox blocks QDialog


I don't really know how to formulate my question this time...

I have my application with a QDialog as a main window. The application is getting different values like temperature, humidity and so on from a remote machine.

For development I added a group box with different widgets to simulate these values. I have different limits for throwing warnings and alarms to the user.

For example if temperature rises over 30°C then I open a QMessageBox with the request time (the application does polling at the remote machine) and the current temperature. So this is updated each request cycle.

I use the show() method to bring up the message box which keeps my application running in background. The problem now is: the focus is at the message box and nothing in my main window/ QDialog can be clicked until the message box is not accepted/ has finished.

And that's my problem: in simulation mode I want to play around with different temperature values which I can adjust by slider in the main window. How can I access these widgets/ make the message box somehow "not-blocking"?

Best regards,

Matthias


Solution

  • What you're experiencing is called "modality" of a window. By default, a QMessageBox is "application modal". This means that input to all other application windows is blocked.

    To change the modality, use setWindowModality() with a value from Qt::WindowModality just before you call show(). In your case:

    box->setWindowModality(Qt::NonModal);
    box->show();