#include #include class MyMainWidget : public QWidget { Q_OBJECT public: MyMainWidget() : mTestNo (0), mCurWidget (0) { mTestNo = 4; setWindowTitle ("Primary"); mPB = new QPushButton ("Next Test", this); connect (mPB, SIGNAL (clicked()), this, SLOT (nextTest())); QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget (mPB); setLayout (layout); } virtual ~MyMainWidget() { delete mCurWidget; } void test (QWidget *w, const QString &text) { w->setWindowTitle ("Secondary"); QString newText = QString ( "%1\n\n" "parentWidget() is %2\n" "className() is %3\n" "isWindow() is %4\n" "windowFlags() is 0x%5\n" "windowModality() is %6") .arg (text) .arg (w->parentWidget() ? w->parentWidget()->metaObject() ->className() : "") .arg (w->metaObject()->className()) .arg (w->isWindow()) .arg (w->windowFlags(), 8, 16, QLatin1Char ('0')) .arg (w->windowModality()); if (w->inherits ("QMessageBox")) { static_cast (w)->setText (newText); } else { QLabel *label = new QLabel (w); label->setText (newText); QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget (label); w->setLayout (layout); } w->show(); if (mCurWidget) { mCurWidget->close(); delete mCurWidget; } mCurWidget = w; } public slots: void nextTest() { switch (mTestNo) { case 0: { QWidget *w = new QWidget(); test (w, "QWidget().\n" "Should have a taskbar entry.\n" "Should not be always on top of parent.\n" "Should not block parent."); break; } case 1: { QWidget *w = new QWidget (this, Qt::Window); test (w, "QWidget (this, Qt::Window).\n" "Should not have a taskbar entry.\n" "Should be always on top of parent.\n" "Should not block parent."); break; } case 2: { QWidget *w = new QDialog(); test (w, "QDialog().\n" "Should have a taskbar entry.\n" "Should not be always on top of parent.\n" "Should not block parent."); break; } case 3: { QWidget *w = new QDialog (this); test (w, "QDialog(this).\n" "Should not have a taskbar entry.\n" "Should be always on top of parent.\n" "Should not block parent."); break; } case 4: { QWidget *w = new QMessageBox(); test (w, "QMessageBox().\n" "Should have a taskbar entry.\n" "Should be always on top of parent.\n" "Should block parent."); break; } case 5: { QWidget *w = new QMessageBox (this); test (w, "QMessageBox (this).\n" "Should not have a taskbar entry.\n" "Should be always on top of parent.\n" "Should block parent."); break; } case 6: { QWidget *w = new QWidget(); w->setWindowModality (Qt::WindowModal); test (w, "QWidget() - WindowModal.\n" "Should have a taskbar entry.\n" "Should not be always on top of parent.\n" "Should not block parent."); break; } case 7: { QWidget *w = new QWidget (this, Qt::Window); w->setWindowModality (Qt::WindowModal); test (w, "QWidget (this, Qt::Window) - WindowModal.\n" "Should not have a taskbar entry.\n" "Should be always on top of parent.\n" "Should block parent."); break; } case 8: { QWidget *w = new QWidget(0, Qt::Dialog); w->setWindowModality (Qt::ApplicationModal); test (w, "QWidget() - ApplicationModal.\n" "Should have a taskbar entry.\n" "Should be always on top of parent.\n" "Should block parent."); break; } case 9: { QWidget *w = new QWidget (this, Qt::Window); w->setWindowModality (Qt::ApplicationModal); test (w, "QWidget (this, Qt::Window) - ApplicationModal.\n" "Should not have a taskbar entry.\n" "Should be always on top of parent.\n" "Should block parent."); break; } default: mPB->setText ("No More Tests"); mPB->setEnabled (false); return; } ++ mTestNo; } private: int mTestNo; QPushButton *mPB; QWidget *mCurWidget; }; int main (int argc, char **argv) { QApplication app (argc, argv); app.setQuitOnLastWindowClosed (true); MyMainWidget mainWidget; mainWidget.resize (100, 100); mainWidget.show(); return app.exec(); } #include "modal.moc"