Qt——P22 其他标准对话框

mainwindow.cpp

#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);

    //点击new按钮 弹出一个颜色对话框
    connect(ui->actionnew, &QAction::triggered, this,[=](){
        QColor color = QColorDialog::getColor(QColor(255, 0, 0));
        qDebug() << "red:" << color.red() << "green:" << color.green() << "blue:" << color.blue();
    });

    //点击open按钮 弹出一个文件对话框
    connect(ui->actionopen, &QAction::triggered, this, [=](){
        //参数1:父亲 参数2:标题 参数3:默认打开路径 参数4:目标文件格式
        //返回值是选择文件的路径
       QString str = QFileDialog::getOpenFileName(this, "open file", "C:\\", "(.txt)");
       qDebug() << str;
    });

    //点击close按钮 弹出字体对话框
    connect(ui->actionclose, &QAction::triggered, this, [=](){
        bool flag;
        QFont font = QFontDialog::getFont(&flag, QFont("楷体", 36));
        qDebug() << "字体:" << font.family().toUtf8().data() << "\n字号" << font.pointSize() << "\n是否加粗:" << font.bold();
    });

//    //点击save按钮 弹出信息对话框
//    connect(ui->actionsave, &QAction::triggered, this, [=](){
//        QString message = "qwe";
//        QMessageBox::information(this, "information", message);
//    });

//    //点击print按钮 弹出提示对话框
//    connect(ui->actionprint, &QAction::triggered, this, [=](){
//        //参数1:父亲 参数2:标题 参数3:内容 参数4:按键类型 参数5:默认关联回车按键
//        if(QMessageBox::Save == QMessageBox::question(this, "print", "tips", QMessageBox::Save|QMessageBox::Help, QMessageBox::Help))
//        {
//            qDebug() << "user click save.";
//        }
//        else
//        {
//            qDebug() << "user click help.";
//        }
//    });

//    //点击exit按钮 弹出警告对话框
//    connect(ui->actionexit, &QAction::triggered, this, [=](){
//        QMessageBox::warning(this, "exit", "warning");
//    });

}

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值