3-3-QmessageDialog、QcolorDialog

文章目录

1、效果

color_dialog
在这里插入图片描述
msg_dialog
在这里插入图片描述

2、代码

widget.cpp

/*
**消息对话框功能的实现
*/
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    Init();
}

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

void Widget::Init()
{
    //信号与槽
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(doProcessClickedPushbtn()));
    connect(ui->btn2,SIGNAL(clicked()),this,SLOT(doProcessClickedColorbtn()));
}

//color_dialog 静态
/ColorDialogue//
void Widget::doProcessClickedColorbtn(){
    qDebug()<<"clicked clor pushbutton"<<endl;

    QColor mycolor = QColorDialog::getColor(Qt::red,this,"get color");
    if(mycolor.isValid()){
        //设置label里面字体颜色
        QPalette pe=ui->label->palette();//获取palettle
        pe.setColor(QPalette::WindowText,mycolor);
        ui->label->setPalette(pe);
    }
}


//msg_dialog 静态
MessageDialogue/
void Widget::doProcessClickedPushbtn()
{
    qDebug()<<"clicked pushbutton"<<endl;

    //about
    //QMessageBox::about(this,"关于","own by xxx xxx xxx");

    //information
    /*
    QMessageBox::StandardButton ret = QMessageBox::information(this,"information","xxxx",
                                     QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel,QMessageBox::Yes);
    if(ret == QMessageBox::Yes)
    {
        qDebug()<<"yes"<<endl;
    }
    else if (ret == QMessageBox::No) {
         qDebug()<<"no"<<endl;
    }
    else if (ret == QMessageBox::Cancel) {
        qDebug()<<"cancel"<<endl;
    }
    */

    //warning
    QMessageBox::StandardButton ret = QMessageBox::warning(this,"wanning","xxxx",
                                      QMessageBox::Yes|QMessageBox::No|QMessageBox::Help,QMessageBox::Help);
    if(ret == QMessageBox::Yes)
    {
        qDebug()<<"yes"<<endl;
    }
    else if (ret == QMessageBox::No) {
         qDebug()<<"no"<<endl;
    }
    else if (ret == QMessageBox::Help) {
        qDebug()<<"help"<<endl;
    }

}

widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QtDebug>
#include <QMessageBox>
#include <QColorDialog>
namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();

private:
    Ui::Widget *ui;

    void Init();
private slots:
    void doProcessClickedPushbtn();
    void doProcessClickedColorbtn();

};


#endif // WIDGET_H

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值