news 2026/2/26 8:01:38

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/2/25 17:42:21

深度学习打卡第J2周:ResNet50V2算法实战与解析

🍨 本文为🔗365天深度学习训练营中的学习记录博客🍖 原作者:K同学啊 import tensorflow as tf import tensorflow.keras.layers as layers from tensorflow.keras.models import Modeldef block2(x, filters, kernel_size3, stri…

作者头像 李华
网站建设 2026/2/25 5:08:47

搜维尔科技:MANUS数据手套实现远程虚拟现实神经外科手术训练

理工学院纳米沉浸式实验室沉浸式实验室是理工学院的多学科空间,旨在可视化复杂数据并开发沉浸式技术原型。它为科学、工程和艺术领域的用户提供增强现实和虚拟现实研究、动作捕捉以及数字物理交互方面的支持。外科手术训练挑战现代神经外科技术对精准度要求极高&…

作者头像 李华
网站建设 2026/2/17 20:20:53

端侧多模态新纪元:MiniCPM-V 2.6重新定义移动端AI交互体验

在人工智能技术迅猛发展的今天,多模态理解能力已成为衡量AI模型智能化水平的核心指标。近日,由OpenBMB团队推出的MiniCPM-V 2.6模型在该领域取得显著进展,尤其在资源受限的端侧设备上展现出令人瞩目的性能表现。这款融合视觉与语言理解能力的…

作者头像 李华
网站建设 2026/2/24 20:27:36

LeetCode 49. 字母异位词分组 | 从排序到计数的哈希表优化之路

在 LeetCode 的字符串类题目中,「字母异位词分组」是一道经典的中等难度题,它不仅考察字符串处理的基础能力,更是对哈希表键值设计思路的深度检验。这道题的核心是找到字母异位词的 共性特征,并通过这个特征实现分组。今天我们就从…

作者头像 李华
网站建设 2026/2/21 18:47:44

亲测!高性价比AI数字员工租赁公司分享

亲测!高性价比AI数字员工租赁公司分享行业痛点分析当前AI数字员工领域面临着诸多技术挑战。一方面,技术的通用性不足,不同行业的业务流程和需求差异巨大,现有的AI数字员工难以实现全行业的深度适配。测试显示,在一些复…

作者头像 李华