PDA

View Full Version : Modal QDialog inside QMdiArea



Nesbitt
6th February 2009, 13:17
Hi

I am trying to use modal (Qt::WindowModal) QDialog inside QMdiArea and it doesn't work.
Here is example code:

#include <QApplication>
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow mainWin;

QMdiArea* area = new QMdiArea();
mainWin.setCentralWidget(area);

//window 1
QWidget* w = new QWidget();
w->setWindowTitle("w");

QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(new QLineEdit());
layout->addWidget(new QTextEdit());
layout->addWidget(new QPushButton("B1"));
w->setLayout(layout);

area->addSubWindow(w);

//window 2
QWidget* w2 = new QWidget();
w2->setWindowTitle("w2");

QVBoxLayout* layout2 = new QVBoxLayout();
layout2->addWidget(new QLineEdit());
layout2->addWidget(new QTextEdit());
layout2->addWidget(new QPushButton("B2"));
w2->setLayout(layout2);

QMdiSubWindow* sw2 = area->addSubWindow(w2);

mainWin.show();

//dialog
QDialog d(sw2);// block window 2
d.setWindowTitle("d");
d.setWindowModality(Qt::WindowModal);

QVBoxLayout* layout3 = new QVBoxLayout();
layout3->addWidget(new QLineEdit());
layout3->addWidget(new QLineEdit());
layout3->addWidget(new QPushButton("B3"));
d.setLayout(layout3);

area->addSubWindow(&d);
d.exec();

return app.exec();
}

Dialog should block window 2, but it deasn't block anything. It looks like ordinary window.

What is the correct way to do this?

Thank you.

Talkless
17th March 2009, 09:21
I'm also trying to do something like that.

I want to have a number of QMdiArea tabs, and in every of them - modal window stack.

It's not working probably because QMdiSubWindow handles all the stuff and it's not modal dialog by origin...