【Qt】消息对话框类
2016-07-16 12:15
585 查看
消息对话框类在前者消息对话框的基础之上完成的
参见:http://blog.csdn.net/ldan508/article/details/51921182
【效果如下】
【添加代码】
添加新的文件msgboxdlg类
//msgboxdlg.h
<span style="font-family:Microsoft YaHei;font-size:18px;">#ifndef MSGBOXDLG_H
#define MSGBOXDLG_H
#include<QLabel>
#include<QPushButton>
#include<QGridLayout>
#include<QDialog>
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
</span>
//msgboxdlg.cpp
<span style="font-family:Microsoft YaHei;font-size:18px;">#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()
{
}
</span>
//dialog.h
<span style="font-family:Microsoft YaHei;font-size:18px;"> 添加头文件
#include "msgboxdlg.h"
添加private成员变量:
QPushButton *MsgBtn;
添加类函数:
MsgBoxDlg *msgDlg;
添加槽函数:
void showMsgDlg();
</span>
//dialog.cpp
<span style="font-family:Microsoft YaHei;font-size:18px;"> 构造函数中添加:
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();
}</span>
参见:http://blog.csdn.net/ldan508/article/details/51921182
【效果如下】
【添加代码】
添加新的文件msgboxdlg类
//msgboxdlg.h
<span style="font-family:Microsoft YaHei;font-size:18px;">#ifndef MSGBOXDLG_H
#define MSGBOXDLG_H
#include<QLabel>
#include<QPushButton>
#include<QGridLayout>
#include<QDialog>
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
</span>
//msgboxdlg.cpp
<span style="font-family:Microsoft YaHei;font-size:18px;">#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()
{
}
</span>
//dialog.h
<span style="font-family:Microsoft YaHei;font-size:18px;"> 添加头文件
#include "msgboxdlg.h"
添加private成员变量:
QPushButton *MsgBtn;
添加类函数:
MsgBoxDlg *msgDlg;
添加槽函数:
void showMsgDlg();
</span>
//dialog.cpp
<span style="font-family:Microsoft YaHei;font-size:18px;"> 构造函数中添加:
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();
}</span>
相关文章推荐
- QT学习 第一章:基本对话框
- 使用Shiboken为C++和Qt库创建Python绑定
- Qt 5.6更新至RC版,最终版本近在咫尺
- Qt定时器和随机数详解
- Qt实现图片移动实例(图文教程)
- Qt for Android开发实例教程
- QModelIndex/Role/Model介紹<二>
- Qt Model/View/Delegate浅谈 - QAbstractListModel
- Qt Model/View/Delegate浅谈 - roleNames()
- QT历程(一):与CryptoJs对应的AES加密
- 基于PyQt5的快速开发框架QFramer
- OSX下安装PyQt
- ok6410开发板移植DirectFB手记
- 【笔记】给Qt内嵌一个Chrome吧
- 【算法】最短路径之A*搜索
- qt入门必备
- 在 Qt4 中使用 C++11
- Hello Word ~ v0.2.2 背单词软件发布 -- By WHYPRO
- ubuntu下opencv和qt的安装配置
- linux下opengl的安装(with qt)