当前位置: 首页 > news >正文

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-弹框提示-界面提醒

http://www.gsyq.cn/news/89724.html

相关文章:

  • 【异常】豆包TTS语音合成常见报错及SSML代码实现解决方案
  • 【项目实战】Vercel 是一个让你的网站“瞬间上线”的云平台。Vercel 现在确实是技术圈的“当红炸子鸡”,尤其是在个人博客和前端开发领域。
  • 【异常】Coze提示WorkflowEventError(errorCode=5000, errorMessage=The request parameter is illegal, see:
  • Python-2. Python语言初识-教学设计
  • 02、打不开某个网站
  • 为什么近视的孩子更推荐眼调节训练灯?不是护眼灯不好,而是需求不一样!
  • 基于SpringBoot + Vue的健身房管理系统
  • 搜维尔科技:MANUS数据手套实现远程虚拟现实神经外科手术训练
  • 团队协作神器!本地部署 ONLYOFFICE + cpolar,多人编辑文档超方便
  • Day28~实现strlen、strcpy、strncpy、strcat、strncat
  • 学习c语言第一天的学习笔记
  • 端侧多模态新纪元:MiniCPM-V 2.6重新定义移动端AI交互体验
  • 技术工具类文章仿写专家Prompt指南
  • 利用用户的通话记录、通讯录以及短信内容可以极大提高销售效率和精准度
  • 【YOLO11-MM 多模态目标检测】动态门控MCFGatedFusion特征融合【自研模块】、抛弃Concat、实现特征动态补偿
  • LeetCode 189. 旋转数组 | 三步反转最优解全拆解
  • 【YOLO11-MM 多模态目标检测】MSAA多尺度特征融合、轻量而且高效、抛弃Concat普通融合
  • 终极英雄联盟智能助手:三步实现游戏自动化完全指南
  • 亲测!高性价比AI数字员工租赁公司分享
  • LLM本地推理全流程:基于LMDeploy的pipeline实战指南
  • OpenAI开源安全推理引擎震撼发布:gpt-oss-safeguard改写AI内容治理规则
  • 匹配回文串:利用KMP算法求解
  • 百度网盘极速下载终极指南:3步实现高速下载体验
  • WebRL-Llama-3.1-8B震撼发布:开源模型突破网页自动化壁垒,42.4%成功率引领行业变革
  • Linux基础命令和工具详解,让你轻松应对各种任务!
  • C语言实现hashmap(附带源码)
  • 阿里通义实验室发布Wan2.2开源视频模型:MoE架构革新引领AIGC创作新范式
  • 职场中令领导同事反感的行为(不定期更新)
  • 5个秘诀让你的Windows右键菜单秒响应:终极解决方案揭秘
  • 超级计算力量:一文看懂GPU并行计算CUDA