C++ (Qt)QMessageBox box(parent);...box.open();
QMessageBox box( (QWidget*) parent );
QMessageBox box( (QWidget*) 0 );box.setParent( parent );
C++ (Qt)for( auto w : qApp->topLevelWindows() ) if( !non_blocking_windows.contains( w ) ) w->setModality( Qt::WindowModal );
C++ (Qt)#include <QtWidgets> QWidget * CreateWin( int index, bool modal ){ QWidget * win = new QWidget; win->setGeometry(index * 100, index * 100, 320, 240); win->setWindowTitle("Win " + QString::number(index)); new QLineEdit("Text " + QString::number(index), win); if (modal) win->setWindowModality(Qt::WindowModal); win->show(); return win;} int main(int argc, char *argv[]){ QApplication app(argc, argv); QWidget * win4 = CreateWin(4, true); QWidget * win3 = CreateWin(3, true); QWidget * win2 = CreateWin(2, false); QWidget * win1 = CreateWin(1, false); // QMessageBox box;// box.exec(); return app.exec();}
C++ (Qt)#include <QtWidgets> QWidget * InitWin( QWidget * win, int index ){ win->setGeometry(index * 100, index * 100, 320, 240); win->setWindowTitle("Win " + QString::number(index)); new QLineEdit("Text " + QString::number(index), win); return win;} int main(int argc, char *argv[]){ QApplication app(argc, argv); QWidget * win1 = InitWin(new QWidget, 1); QWidget * win2 = InitWin(new QWidget, 2); QWidget * win3 = InitWin(new QWidget(win1, Qt::Window), 3); QWidget * win4 = InitWin(new QWidget(win1, Qt::Window), 4); win3->setWindowModality(Qt::WindowModal); win4->setWindowModality(Qt::WindowModal); win1->show(); win2->show(); win3->show(); win4->show(); // QMessageBox box;// box.exec(); return app.exec();}