PDA

View Full Version : WindowModal vs ApplicationModal



drhex
23rd September 2009, 08:58
This program shows a QLineEdit and a QPushButton. When you push the button, a dialog appears. I want it to be possible to keep editing the QLineEdit while the dialog is shown. (Qt-4.6.0-tp1)


#include <QApplication>
#include <QPushButton>
#include <QLineEdit>
#include <QMessageBox>
#include <QLabel>

class Button : public QPushButton
{
Q_OBJECT
public:
Button(QString t) : QPushButton(t)
{
connect(this, SIGNAL(clicked()), this, SLOT(bom()));
}
public slots:
void bom() {
QLabel dummyparent;
QMessageBox::question(&dummyparent, "Modality", "Can you still edit the QLineEdit?");
}
};


int main( int argc, char **argv )
{
QApplication app( argc, argv );

QLineEdit *le = new QLineEdit("edit me");
le->show();

Button *but = new Button("Push Me");
but->show();

return app.exec();
}

#include "prog.moc"

In the docs, it says that a dialog will be WindowModal as opposed to ApplicationModal if it has a parent, so I gave it a dummy parent, hoping it would then not block input to my QLineEdit, but it does.

From docs about Qt::WindowModal:

"The window is modal to a single window hierarchy and blocks input to its parent window, all grandparent windows, and all siblings of its parent and grandparent windows."

Does this mean that a top level-window is considered a sibling to all other top-level windows?

I know I could forgo the convenient static QMessageBox methods and build a dialog by setting properties one by one, showing it and then running some sort of event lopp until it's done, but I was looking for a simpler way of making the dialog less modal.