news 2026/5/7 5:51:54

QDialog-基础讲解

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
QDialog-基础讲解

注意:前面都是基础讲解,如果有什么不懂的可以看看,但是如果只是想看实际运用场景,建议只看自定义案例

这里是目录标题

  • 自定义案例
  • 问题互动
  • 案例互动

The QDialog class is the base class of dialog windows
QDialog 类是对话框窗口的基类

详细解释
A dialog window is a top-level window mostly used for short-term tasks and brief communications with the user. QDialogs may be modal or modeless. QDialogs can provide a return value, and they can have default buttons. QDialogs can also have a QSizeGrip in their lower-right corner, using setSizeGripEnabled().Note that QDialog (and any other widget that has type Qt::Dialog) uses the parent widget slightly differently from other classes in Qt. A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent’s top-level widget (if it is not top-level itself). It will also share the parent’s taskbar entry.
Use the overload of the QWidget::setParent() function to change the ownership of a QDialog widget. This function allows you to explicitly set the window flags of the reparented widget; using the overloaded function will clear the window flags specifying the window-system properties for the widget (in particular it will reset the Qt::Dialog flag).
Note: The parent relationship of the dialog does not imply that the dialog will always be stacked on top of the parent window. To ensure that the dialog is always on top, make the dialog modal. This also applies for child windows of the dialog itself. To ensure that child windows of the dialog stay on top of the dialog, make the child windows modal as well.

对话框窗口是主要用于短期任务和与用户简短交流的顶层窗口。QDialog可以是模态或非模态的,能够提供返回值并设置默认按钮。通过在右下角启用setSizeGripEnabled(),QDialog还可以包含尺寸调整手柄。需注意QDialog(以及任何具有Qt::Dialog类型的部件)对父部件的处理方式与Qt其他类略有不同:对话框始终是顶层部件,但若设置了父部件,其默认位置将居中显示在父部件的顶层窗口之上(若父部件本身非顶层)。对话框还会共享父部件的任务栏条目。通过QWidget::setParent()函数的重载版本可变更QDialog部件的所有权关系,该函数允许显式设置重新指定父部件后的窗口标志;使用重载函数将清除指定部件窗口系统属性的标志(特别是会重置Qt::Dialog标志)。
注意:对话框的父级关系并不意味着对话框始终堆叠在父窗口之上。要确保对话框始终置顶,需将其设为模态。此规则同样适用于对话框自身的子窗口——要使对话框的子窗口保持置顶状态,也需将这些子窗口设为模态。

自定义案例

MaintenanceDialog::MaintenanceDialog(QWidget*parent):QDialog(parent){setWindowTitle("个人信息记录");setMinimumSize(500,400);QFormLayout*formLayout=newQFormLayout();m_adaptationParams=newQLineEdit(this);m_softwareUpdate=newQLineEdit(this);m_calibrationProcess=newQLineEdit(this);m_keyComponentTestParams=newQLineEdit(this);m_replacementInfo=newQLineEdit(this);formLayout->addRow("姓名:",m_adaptationParams);formLayout->addRow("年龄:",m_softwareUpdate);formLayout->addRow("性别:",m_calibrationProcess);formLayout->addRow("爱好:",m_keyComponentTestParams);formLayout->addRow("目标:",m_replacementInfo);m_saveButton=newQPushButton("保存",this);QVBoxLayout*mainLayout=newQVBoxLayout(this);mainLayout->addLayout(formLayout);mainLayout->addWidget(m_saveButton,0,Qt::AlignRight);setLayout(mainLayout);connect(m_saveButton,&QPushButton::clicked,this,&MaintenanceDialog::onSaveButtonClicked);}

问题互动

弹出来的界面,被置顶后,原有界面是否还会存在?

假设存在,如下图,有什么办法,在没有完成当前界面任务前,不能使之点击其它任务?
揭秘:

voidMainWindow::onShowMaintenanceDialog(){m_dialog->exec();}

案例互动

qt-弹框提示-界面提醒

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/5 9:09:45

基于SpringBoot + Vue的养老院管理系统

文章目录前言一、详细操作演示视频二、具体实现截图三、技术栈1.前端-Vue.js2.后端-SpringBoot3.数据库-MySQL4.系统架构-B/S四、系统测试1.系统测试概述2.系统功能测试3.系统测试结论五、项目代码参考六、数据库代码参考七、项目论文示例结语前言 💛博主介绍&#…

作者头像 李华
网站建设 2026/5/2 18:19:27

团队协作神器!本地部署 ONLYOFFICE + cpolar,多人编辑文档超方便

文章目录前言1. 安装Docker2. 本地安装部署ONLYOFFICE3. 安装cpolar内网穿透4. 固定OnlyOffice公网地址前言 ONLYOFFICE 是一款在线办公套件,支持文档、表格、演示文稿的在线编辑,兼容 Office 格式,还能实时多人协作,特别适合中小…

作者头像 李华
网站建设 2026/5/1 9:55:36

搜维尔科技:Xsens独立项目-面向独立工作室的高端动作捕捉

像专业工作室一样拍摄,像独立电影人一样创作独立游戏开发计划旨在扶持新兴人才,让他们更容易获得AAA级动作捕捉技术。更重要的是,它为独立游戏开发者、新兴工作室和游戏开发商提供了一种更经济实惠的方式,让他们能够在不牺牲质量的…

作者头像 李华
网站建设 2026/5/1 11:14:07

【YOLO11-MM 多模态目标检测】动态门控MCFGatedFusion特征融合【自研模块】、抛弃Concat、实现特征动态补偿

摘要 本文提出了一种基于动态门控特征融合模块(MCFGatedFusion)的YOLO11-MM多模态目标检测框架改进方案。该模块通过可学习的门控机制实现红外与可见光特征的自适应融合,采用零初始化策略确保训练稳定性,支持add和concat两种融合模式。实验表明,该方法在FLIR、M3FD等数据…

作者头像 李华
网站建设 2026/5/2 8:22:03

腾讯AngelSlim开源项目深度解析:AI驱动的开发者协作新范式

在当今数字化浪潮席卷全球的背景下,开源社区已成为推动技术创新的核心引擎。腾讯作为全球领先的互联网科技公司,始终积极投身开源事业,近日其在Gitcode平台上发布的AngelSlim项目引发了业界广泛关注。该项目以222星标和26次分支 Fork 的成绩&…

作者头像 李华
网站建设 2026/5/1 5:49:20

Linux基础命令和工具详解,让你轻松应对各种任务!

grep 命令用于在文件中执行关键词搜索,并显示匹配的效果。部分常用选项 :-c 仅显示找到的行数-i 忽略大小写-n 显示行号-v 反向选择 – 仅列出没有关键词的行。v 是 invert 的缩写。-r 递归搜索文件目录-C n 打印匹配行的前后n行(1&#xff0…

作者头像 李华