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

QT 对话框

对话框 模态对话框(没有关闭不能操作其他窗口),非模态对话框

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDialog> //对话框
#include<QMessageBox>//消息对话框
#include<QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //使用添加QT资源文件 ": + 前缀名 + 文件名"
    ui->actionNew->setIcon(QIcon(":/Images/New.png"));
    ui->actionOpen->setIcon(QIcon(":/Images/open.png"));

    //对话框 模态对话框(没有关闭不能操作其他窗口),非模态对话框
    //模态创建 阻塞
    connect(ui->actionNew,& QAction::triggered,[=](){

        //模态创建 exec() 阻塞
        QDialog dialog(this);
        dialog.resize(200,100);
        dialog.setWindowTitle("新建文件");
        dialog.exec();

    });

    connect(ui->actionOpen,& QAction::triggered,[=](){
        //非模态创建 show(),还要new
        QDialog *dialogShow = new QDialog(this);
        dialogShow->resize(200,100);
        dialogShow->setWindowTitle("打开文件");
        //解决对话框打开,关闭后要等到父窗口关闭后才会释放内存对象的问题。
        //这样写后,只要对话框关闭内存就释放
        dialogShow->setAttribute(Qt::WA_DeleteOnClose);
        dialogShow->show();
    });

    //标准对话框
    //消息对象框,错误
    connect(ui->actionCritical,& QAction::triggered,[=](){
        QMessageBox::critical(this,"错误对话框标题","这是一个错误对话框显示的错误内容");
    });

    //信息对话框
    connect(ui->actionInfo,& QAction::triggered,[=](){
        QMessageBox::information(this,"信息对话框标题","提示信息内容");
    });

    //问题对话框
    connect(ui->actionQuest,& QAction::triggered,[=](){
        //
        //question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = StandardButtons(Yes | No), QMessageBox::StandardButton defaultButton = NoButton)
        //QWidget *parent 指定父亲
        //const QString &title 标题
        //const QString &text 内容
        //QMessageBox::StandardButtons buttons = StandardButtons(Yes | No) 在对话框中显示的按钮
        //QMessageBox::StandardButton defaultButton = NoButton) 回车默认按钮
        QMessageBox::StandardButton messageBoxResult = QMessageBox::question(this,"问题对话框标题","你确定要删除吗?", QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
        if(messageBoxResult == QMessageBox::Yes)
        {
            qDebug() << "选择的是_Yes";
        }
        else
        {
            qDebug() << "选择的是_No";
        }
    });

    connect(ui->actionWarning,& QAction::triggered,[=](){
        QMessageBox::warning(this,"报警标题","报警内容");
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}


http://www.kler.cn/news/358266.html

相关文章:

  • [k8s理论知识]3.docker基础(二)隔离技术
  • 百度SEO前10关键词排名波动跟用户行为反馈有很大关系
  • UG NX12.0建模入门笔记:1.2 鼠标的基本操作
  • 【VUE小型网站开发】初始环境搭建
  • RNN,LSTM,GRU的区别和联系? RNN的梯度消失问题?如何解决?
  • Widget结构(一)
  • 基于SpringBoot+Vue的厨艺交流系统的设计与实现(源码+定制开发)厨艺知识与美食交流系统开发、在线厨艺分享与交流平台开发、智能厨艺交流与分享系统开发
  • 【文心智能体 | AI大师工坊】如何使用智能体插件,完成一款购物类智能体的开发,来体验一下我的智能体『科技君Tom』
  • 爬虫实现验证码登录古诗文网【爬虫学习day.02】
  • 【高等数学】无穷级数
  • Win11 安装 PostgreSQL 报错解决方案
  • 【小洛的VLOG】Web 服务器高并发压力测试(Reactor模型测试)
  • 【环境搭建】Windows系统中使用VScode在虚拟机ubuntu系统中进行开发的方法
  • C++ 算法学习——1.9 Kruskal算法
  • 平安养老险深圳分公司:创新养老服务,深入践行金融为民
  • SQLite数据库在Android中的应用及操作方式
  • Python | Leetcode Python题解之第486题预测赢家
  • leetcode day1
  • Python Django 查询集的延迟加载特性
  • BERT论文关键点解读与常见疑问