PDA

View Full Version : Modal dialog only modal to base window?



SvenA
9th April 2015, 17:39
Hello!

I'm trying to create an multiple window application and have problems with the
modal dialogs.

My basic code is the following:


MainWindow *mainWin = new MainWindow;
mainWin->show();

In the MainWindow class I have the following function:


void MainWindow::newWindow()
{
MainWindow *mainWin = new MainWindow;
mainWin->show();
}

This works fine.

But, the modal dialogs executed from the MainWindow class (for adding/editing data)
block any showed windows. I expected the dialogs only to block the (base) main window
it was called from, but instead it blocked any other main windows too.

Is this so by Qt's design or is there any way to change this behavior?

Regards
Sven

yeye_olive
9th April 2015, 18:16
Whenever you create a QDialog, call setModality(Qt::WindowModal) to override the default behavior (Qt::ApplicationModal) which blocks all windows in the application.

SvenA
9th April 2015, 20:18
Thank you for the hint!
I did' see this method.

To be correct, it is this function:


setWindowModality(Qt::WindowModal);


Regards
Sven

yeye_olive
10th April 2015, 10:25
Oops, my bad. I indeed meant setWindowModality().