Qt教程:对话框

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDialog>
#include <QDebug>
#include <QMessageBox>
#include <QColorDialog>
#include <QFileDialog>
#include <QFontDialog>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //点击新建按钮,弹出一个对话框
    connect(ui->actionnew,&QAction::triggered,[=](){
        //对话框 分类
        //模态对话框(不可以对其他窗口进行操作) 非模态对话框(可以对其他窗口进行操作)

        //模态创建
//        QDialog dlg(this);
//        dlg.resize(200,100);
//        //阻塞功能
//        dlg.exec();

//        qDebug() << "模态对话框弹出了" ;

        //非模态对话框
        //防止一闪而过,创建在堆区
//        QDialog *dlg2 = new QDialog(this);
//        dlg2->resize(200,100);
//        dlg2->show();
//        //防止内存泄漏,55号属性
//        dlg2->setAttribute(Qt::WA_DeleteOnClose);
//        qDebug() << "非模态对话框弹出了" ;

        //消息对话框
        //错误对话框
        //QMessageBox::critical(this,"critical","错误!");

        //信息对话框
        //QMessageBox::information(this,"信息","你好啊!!");

        //提问对话框
        //参数1 父亲 参数2 标题 参数3 提示内容 参数4 按键类型 参数5 默认关联回车按键
//        if(QMessageBox::Save == QMessageBox::question(this,"ques","提问",QMessageBox::Save|QMessageBox::Cancel,QMessageBox::Cancel))
//        {
//            qDebug() << "选择的是保存";
//        }
//        else
//        {
//            qDebug() << "选择的是取消";
//        }

        //警告对话框
        //QMessageBox::warning(this,"警告","warning!!!");

        //其他标准对话框
        //颜色对话框
//        QColor color = QColorDialog::getColor(QColor(255,0,0));
//        qDebug() << "r = " << color.red() << " g = " << color.green()
//                 << " b = " << color.blue();

        //文件对话框 参数1 父亲 参数2 标题 参数3 默认打开路径 参数4 过滤文件格式
        //返回值是 选取的路径
//        QString str = QFileDialog::getOpenFileName(this,"打开文件","C:\\Users\\32780\\Desktop","(*.txt)");
//        qDebug() << str;

        //字体对话框
        bool flag;
        QFont font = QFontDialog::getFont(&flag,QFont("华文彩云",36));
        qDebug() << "字体:" << font.family() << " 字号:"
                 << font.pointSize() << " 是否加粗:" << font.bold();



    });
}

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值