forked from GLDsuh-a/qt-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgboxdlg.cpp
118 lines (103 loc) · 3.71 KB
/
msgboxdlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "msgboxdlg.h"
#include <QMessageBox>
MsgBoxDlg::MsgBoxDlg(QWidget *parent) :
QDialog(parent)
{
setWindowTitle(QStringLiteral("标准消息对话框的实例")); //设置对话框的标题
label = new QLabel;
label->setText(QStringLiteral("请选择一种消息框"));
questionBtn = new QPushButton;
questionBtn->setText(QStringLiteral("QuestionMsg"));
informationBtn = new QPushButton;
informationBtn->setText(QStringLiteral("InformationMsg"));
warningBtn = new QPushButton;
warningBtn->setText(QStringLiteral("WarningMsg"));
criticalBtn = new QPushButton;
criticalBtn->setText(QStringLiteral("CriticalMsg"));
aboutBtn = new QPushButton;
aboutBtn->setText(QStringLiteral("AboutMsg"));
aboutQtBtn = new QPushButton;
aboutQtBtn->setText(QStringLiteral("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()),this,SLOT(showQuestionMsg()));
connect(informationBtn,SIGNAL(clicked()),this,SLOT(showInformationMsg()));
connect(warningBtn,SIGNAL(clicked()),this,SLOT(showWarningMsg()));
connect(criticalBtn,SIGNAL(clicked()),this,SLOT(showCriticalMsg()));
connect(aboutBtn,SIGNAL(clicked()),this,SLOT(showAboutMsg()));
connect(aboutQtBtn,SIGNAL(clicked()),this,SLOT(showAboutQtMsg()));
}
void MsgBoxDlg::showQuestionMsg()
{
label->setText(QStringLiteral("Question Message Box"));
switch(QMessageBox::question(this, QStringLiteral("Question Message"),
QStringLiteral("you have completed, if you want to end this"),
QMessageBox::Ok | QMessageBox::Cancel,
QMessageBox::Ok))
{
case QMessageBox::Ok:
label->setText("Question button/Ok");
break;
case QMessageBox::Cancel:
label->setText("Question button/Cancel");
break;
default:
break;
}
return;
}
void MsgBoxDlg::showInformationMsg()
{
label->setText(QStringLiteral("Information Message Box"));
QMessageBox::information(this,QStringLiteral("Information Message Frame"),
QStringLiteral("this is information test, Welcome"));
return;
}
void MsgBoxDlg::showWarningMsg()
{
label->setText(QStringLiteral("Warning Message Box"));
switch(QMessageBox::warning(this,QStringLiteral("Warning Message"),
QStringLiteral("您修改的内容还未保存,是否要保存对文档的修改?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save))
{
case QMessageBox::Save:
label->setText(QStringLiteral("Warning button/Save"));
break;
case QMessageBox::Discard:
label->setText(QStringLiteral("Warning button/Discard"));
break;
case QMessageBox::Cancel:
label->setText(QStringLiteral("Warning button/Cancel"));
break;
default:
break;
}
return;
}
void MsgBoxDlg::showCriticalMsg()
{
label->setText(QStringLiteral("Critical Message Box"));
QMessageBox::critical(this,QStringLiteral("Critical Message"),QStringLiteral("this is critical message"));
return;
}
void MsgBoxDlg::showAboutMsg()
{
label->setText(QStringLiteral("About Message Box"));
QMessageBox::about(this,QStringLiteral("About"),QStringLiteral("this is about message"));
return;
}
void MsgBoxDlg::showAboutQtMsg()
{
label->setText(QStringLiteral("About Qt Message Box"));
QMessageBox::aboutQt(this,QStringLiteral("About Qt Message"));
return;
}