PDA

View Full Version : mainwindow modality



user
11th July 2008, 00:54
I have a mainWindow application which can start 3 sub-applications. Each of the sub-applications can be started independently or through the main application so each of those sub-applications is also a mainWindow application.
One of the sub-applications (A) also can be started from another sub-application (B).
When I start (A) from (B), (A) is a mainWindow which I set to applicationModal, I get the required behaviour: (B) is not responding as long as (A) is open.
My problem is if the same scenario happens but when (B) is started from the top mainWindow application, things don't work as I want.

In the top mainWindow I have:

B * firstChild;
firstChild= new B(this);

// earlier in the code - QWorkspace * workspace; and setCentralWidget(workspace);
workspace->addWindow(firstChild);
firstChild->setAttribute(Qt::WA_DeleteOnClose);
firstChild->setAttribute(Qt::WA_NoMousePropagation);
firstChild->show()

In application B:

A * secondChild;
secondChild= new A(this);
secondChild->setAttribute(Qt::WA_DeleteOnClose);
secondChild->setWindowModality(Qt::ApplicationModal);
secondChild->show();

As the code looks above - secondChild window is opened outside the workspace window and firstChild is not available until secondChild is closed (good).
But I want the secondChild window to open inside the same workspace as the firstChild window. So before I show secondChild, I add the line:

static_cast<QWorkspace*>( static_cast<QMainWindow*>(parent)->centralWidget() )->addWindow(secondChild);

This opens the secondChild window in the workspace but I cannot set the modality properly - it seems to lock the whole application and I cannot click on anything (not even secondChild window).

What Am I doing wrong?