QT模态与非模态的设置

Qt有两种方法可以实现模态窗口:
(1)使用QDialog窗口->exec(); //阻塞整个程序所有窗口
(2)使用setModal()函数来实现; //阻塞整个程序所有窗口
(3)使用setWindowModality(Qt::ApplicationModal);//阻塞整个窗口

示例代码:

//方法一
//绑定父指针后此指针不需要delete
ModelDialog *model = new ModelDialog(this);
//设置窗口状态为模态窗口
model->setModal(true);
model->show();

//方法二
ModelDialog *model = new ModelDialog(this);
model->exec();

//方法三 《在即将显示窗口的构造中进行设置即可》
setWindowModality(Qt::NonModal);			//不阻塞任何窗口
setWindowModality(Qt::ApplicationModal);	//阻塞整个窗口

我用的第三种 

猜你喜欢

转载自blog.csdn.net/m0_48990191/article/details/113589299