news 2026/7/12 1:56:59

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/7/11 3:33:50

Day28~实现strlen、strcpy、strncpy、strcat、strncat

实现strlen、strcpy、strncpy、strcat、strncat#include <stdio.h>size_t my_strlen(const char *src) {size_t len 0;while (*src ! \0){len;src;}return len; }char *my_strcpy(char *dest, const char *src) {if (dest NULL || src NULL) // 判断输入的字符是否为空…

作者头像 李华
网站建设 2026/7/11 16:10:16

空洞骑士模组管理大师课:5个关键技巧让Scarab成为你的游戏管家

你是否曾经因为模组冲突而无法正常游戏&#xff1f;或者因为手动安装模组耗费了大量时间&#xff1f;Scarab作为一款专为空洞骑士设计的模组管理工具&#xff0c;正是你需要的解决方案。这款基于Avalonia框架开发的开源工具&#xff0c;让模组安装、更新和卸载变得前所未有的简…

作者头像 李华
网站建设 2026/7/11 15:17:22

实用方法:轻松实现NCM文件格式转换的完整解析

实用方法&#xff1a;轻松实现NCM文件格式转换的完整解析 【免费下载链接】NCMconverter NCMconverter将ncm文件转换为mp3或者flac文件 项目地址: https://gitcode.com/gh_mirrors/nc/NCMconverter NCMconverter是一款高效便捷的开源工具&#xff0c;专门用于将网易云音…

作者头像 李华
网站建设 2026/7/12 8:37:11

C++课后习题训练记录Day49

1.练习项目&#xff1a; 输入描述 第一行是一个整数 M&#xff08;1≤M≤1000&#xff09;&#xff0c;表示一共有 M 次操作。 第二行到第 M1 行输入操作&#xff0c;格式如下&#xff1a; IN name VOUT VIN name NOUT N 输出描述 输出 M 次操作后 VIP 窗口队列和普通窗口…

作者头像 李华
网站建设 2026/7/11 21:48:32

LeetCode 189. 旋转数组 | 三步反转最优解全拆解

「旋转数组」核心考察数组操作技巧与空间复杂度优化思路。这道题看似简单&#xff0c;却能延伸出多种解题方法&#xff0c;从暴力模拟到极致的空间优化&#xff0c;层层递进的思路能帮我们理解算法设计的核心 —— 用最少的资源解决问题。实际开发中&#xff0c;类似 循环数组操…

作者头像 李华
网站建设 2026/7/11 20:43:52

downkyi视频下载:告别卡顿与画质损失的终极解决方案

downkyi视频下载&#xff1a;告别卡顿与画质损失的终极解决方案 【免费下载链接】downkyi 哔哩下载姬downkyi&#xff0c;哔哩哔哩网站视频下载工具&#xff0c;支持批量下载&#xff0c;支持8K、HDR、杜比视界&#xff0c;提供工具箱&#xff08;音视频提取、去水印等&#xf…

作者头像 李华