-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMsgBoxEx.cpp
83 lines (74 loc) · 2.6 KB
/
MsgBoxEx.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
#include "MsgBoxEx.h"
MsgBoxEx::MsgBoxEx(QWidget *parent) : QMessageBox(parent)
{
setWindowIcon(QIcon("./res/icon/sys.png"));
setWindowTitle(QString::fromLocal8Bit("系统提示"));
m_pBtnCancel = addButton(QString::fromLocal8Bit("取消"), QMessageBox::AcceptRole);
m_pBtnOk = addButton(QString::fromLocal8Bit("确定"), QMessageBox::AcceptRole);
// 按钮建立信号槽
connect(m_pBtnOk, SIGNAL(clicked()), this, SLOT(onOkClicked()));
connect(m_pBtnCancel, SIGNAL(clicked()), this, SLOT(onCancelClicked()));
}
void MsgBoxEx::setMsgBoxMode(QString content, int delayTime)
{
m_strContent = content;
m_nDelayTime = delayTime;
m_msgBoxMode = MsgBoxMode::MsgBoxMode_OnlyHint;
updateMsgBoxMode();
}
void MsgBoxEx::setMsgBoxMode(QString content, QString title, MsgBoxBtnType btnType)
{
m_strContent = content;
m_strTitle = title;
m_msgBoxBtnType = btnType;
m_msgBoxMode = MsgBoxMode::MsgBoxMode_Normal;
updateMsgBoxMode();
}
void MsgBoxEx::updateMsgBoxMode()
{
setWindowFlags(Qt::FramelessWindowHint);
setText("\n"+m_strContent);
switch (m_msgBoxMode)
{
case MsgBoxMode::MsgBoxMode_OnlyHint:
{
removeButton(m_pBtnOk);
removeButton(m_pBtnCancel);
setStyleSheet("QMessageBox{background-color:#000000}\
QLabel{font: 12pt Microsoft YaHei; font-weight: bold; color:#FFFFFF}");
addButton(QMessageBox::Ok);
button(QMessageBox::Ok)->hide();
show();
QTimer::singleShot(m_nDelayTime, this, SLOT(close()));
exec();
}
break;
case MsgBoxMode::MsgBoxMode_Normal:
{
setStyleSheet("QMessageBox{background-color:#000000}\
QLabel{font: 12pt Microsoft YaHei; font-weight: bold; color:#FFFFFF}\
QPushButton{background:#FFFFFF; border-radius:5px; font-size:10pt; \
font-family:Microsoft YaHei; color:#000000; width:65; height:25} \
QPushButton::hover{background:#4EB485; color:#FFFFFF} \
QPushButton::pressed{background:#34373E; color:#FFFFFF}");
switch(m_msgBoxBtnType)
{
case MsgBoxBtnType_Ok:
removeButton(m_pBtnCancel);
break;
case MsgBoxBtnType_OkCancle:
break;
}
exec();
}
break;
}
}
void MsgBoxEx::onOkClicked()
{
emit btnOkClicked();
}
void MsgBoxEx::onCancelClicked()
{
emit btnCancelClicked();
}