Qt 之模式、非模式、半模式对话框 您所在的位置:网站首页 模式窗体显示为模式对话框怎么设置出来 Qt 之模式、非模式、半模式对话框

Qt 之模式、非模式、半模式对话框

2024-07-14 12:53| 来源: 网络整理| 查看: 265

作者: 一去、二三里 个人微信号: iwaleon 微信公众号: 高效程序员

关于“模式”和“非模式”对话框,相信大家都比较熟悉,但其中有一个可能很多人都比较陌生,介于两者之间的状态,我们称之为“半模式“。

模式对话框 描述

阻塞同一应用程序中其它可视窗口输入的对话框。模式对话框有自己的事件循环,用户必须完成这个对话框中的交互操作,并且关闭了它之后才能访问应用程序中的其它任何窗口。模式对话框仅阻止访问与对话相关联的窗口,允许用户继续使用其它窗口中的应用程序。

显示模态对话框最常见的方法是调用其exec()函数,当用户关闭对话框,exec()将提供一个有用的返回值,并且这时流程控制继续从调用exec()的地方进行。通常情况下,要获得对话框关闭并返回相应的值,我们连接默认按钮,例如:”确定”按钮连接到accept()槽,”取消”按钮连接到reject()槽。另外我们也可以连接done()槽,传递给它Accepted或Rejected。

效果

这里写图片描述

源码 MainWindow *pMainWindow = new MainWindow(); pMainWindow->setWindowTitle(QStringLiteral("主界面")); pMainWindow->show(); CustomWindow *pDialog = new CustomWindow(pMainWindow); pDialog->setWindowTitle(QStringLiteral("模式对话框")); // 关键代码 pDialog->exec(); // 关闭模态对话框以后才会执行下面的代码 pMainWindow->setWindowTitle(QStringLiteral("主界面-模式对话框")); qDebug() setWindowTitle(QStringLiteral("主界面")); pMainWindow->show(); CustomWindow *pDialog = new CustomWindow(pMainWindow); pDialog->setWindowTitle(QStringLiteral("非模式对话框")); // 关键代码 pDialog->show(); // 下面的代码会立即运行 pMainWindow->setWindowTitle(QStringLiteral("主界面-非模式对话框")); qDebug() setWindowTitle(QStringLiteral("主界面")); pMainWindow->show(); CustomWindow *pDialog = new CustomWindow(pMainWindow); pDialog->setWindowTitle(QStringLiteral("半模式对话框")); // 关键代码 pDialog->setModal(true); pDialog->show(); // 下面的代码会立即运行 pMainWindow->setWindowTitle(QStringLiteral("主界面-半模式对话框")); qDebug()


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有