【Qt】消息对话框类

消息对话框类在前者消息对话框的基础之上完成的

参见:http://blog.csdn.net/ldan508/article/details/51921182


【效果如下】

【Qt】消息对话框类_第1张图片     【Qt】消息对话框类_第2张图片



【添加代码】

添加新的文件msgboxdlg类

//msgboxdlg.h

#ifndef MSGBOXDLG_H
#define MSGBOXDLG_H
#include
#include
#include
#include

class MsgBoxDlg : public QDialog
{
    Q_OBJECT
public:
    MsgBoxDlg(QWidget* parent=0);
private slots:
    void showQuestionMsg();
    void showInformationMsg();
    void showWarningMsg();
    void showCriticalMsg();
    void showAboutMsg();
    void showAboutQtMsg();
private:
    QLabel *label;
    QPushButton *questionBtn;
    QPushButton *informationBtn;
    QPushButton *warningBtn;
    QPushButton *criticalBtn;
    QPushButton *aboutBtn;
    QPushButton *aboutQtBtn;
    QGridLayout *mainLayout;
};

#endif // MSGBOXDLG_H


//msgboxdlg.cpp

#include "msgboxdlg.h"

MsgBoxDlg::MsgBoxDlg(QWidget *parent) :
    QDialog(parent)
{
    setWindowTitle(tr("标注信息对话框的实例"));  //设置对话框的标题
    label = new QLabel;
    label->setText(tr("请选择一种消息框"));

    questionBtn = new QPushButton;
    questionBtn->setText(tr("QusetionMsg"));

    informationBtn = new QPushButton;
    informationBtn->setText(tr("InformationMsg"));

    warningBtn = new QPushButton;
    warningBtn->setText(tr("WarningMsg"));

    criticalBtn =new QPushButton;
    criticalBtn->setText(tr("CriticalMsg"));

    aboutBtn = new QPushButton;
    aboutBtn->setText(tr("AboutMsg"));

    aboutQtBtn =new QPushButton;
    aboutQtBtn->setText(tr("AboutQtMsg"));

    //布局
    mainLayout =new QGridLayout(this);
    mainLayout->addWidget(label,0,0,1,2);
    mainLayout->addWidget(questionBtn,1,0);
    mainLayout->addWidget(informationBtn,1,1);
    mainLayout->addWidget(warningBtn,2,0);
    mainLayout->addWidget(criticalBtn,2,1);
    mainLayout->addWidget(aboutBtn,3,0);
    mainLayout->addWidget(aboutQtBtn,3,1);

    //事件关联
    connect(questionBtn,SIGNAL(clicked(bool)),this,SLOT(showQuestionMsg()));
    connect(informationBtn,SIGNAL(clicked(bool)),this,SLOT(showInformationMsg()));
    connect(warningBtn,SIGNAL(clicked(bool)),this,SLOT(showWarningMsg()));\
    connect(criticalBtn,SIGNAL(clicked(bool)),this,SLOT(showCriticalMsg()));
    connect(aboutBtn,SIGNAL(clicked(bool)),this,SLOT(showAboutMsg()));
    connect(aboutQtBtn,SIGNAL(clicked(bool)),this,SLOT(showAboutQtMsg()));

}

void MsgBoxDlg::showQuestionMsg()
{

}

void MsgBoxDlg::showInformationMsg()
{

}

void MsgBoxDlg::showWarningMsg()
{

}

void MsgBoxDlg::showCriticalMsg()
{

}

void MsgBoxDlg::showAboutMsg()
{

}

void MsgBoxDlg::showAboutQtMsg()
{

}


//dialog.h


 添加头文件
#include "msgboxdlg.h" 

添加private成员变量:
 QPushButton *MsgBtn;

添加类函数:
 MsgBoxDlg *msgDlg;

添加槽函数:
void showMsgDlg();



//dialog.cpp

 构造函数中添加:
 MsgBtn =new QPushButton;
 MsgBtn->setText(tr("标准消息对话框实例"));
   mainLayout->addWidget(MsgBtn,3,1);
   connect(MsgBtn,SIGNAL(clicked(bool)),this,SLOT(showMsgDlg()));

槽函数的实现:
void Dialog::showMsgDlg()
{
    msgDlg =new MsgBoxDlg();
    msgDlg->show();
}


你可能感兴趣的:(qt,整理,学习笔记,Qt)