I have a QDialog, and I read a lot about the differences between show (), exec (), and open (). Unfortunately, I did not find a solution to change the modality of the dialog at runtime. I have an application, and from there my QDialog starts. I have a toggle button in this dialog box, and when I click on it, QDialog must change the modality so that it can interact with the application - but this should not happen all the time - only when checking the toggle button.
Is there a possibility? I could not solve the problem with setting setModal (true / false), it just allows me to launch it modally, switch the button and set it to non-modal, but then I can not return to modal.
Here is the code:
Dialog launch:
from the main window:
_dialog = new ToggleModalDialog(this, id, this); _dialog->setWindowModality(Qt::ApplicationModal); _dialog->open();
and here in the switchable slot in ToggleModalDialog
void ToggleModalDialog::changeModality(bool checkState) { if(checkState) { this->setWindowModality(Qt::NonModal); ui->changeModalityButton->setChecked(true); this->setModal(false); } else { this->setWindowModality(Qt::ApplicationModal); ui->changeModalityButton->setChecked(true); }
Thanks in advance!
source share