-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog.cpp
119 lines (100 loc) · 3.51 KB
/
dialog.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
117
118
119
#include "dialog.h"
#include "inputdlg.h"
#include <QString>
#include <QColorDialog>
#include <QFontDialog>
#include <QPixmap>
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
fileBtn = new QPushButton;
fileBtn->setText(QStringLiteral("文件标准对话框实例"));
fileLineEdit = new QLineEdit;
colorBtn = new QPushButton;
colorBtn->setText(QStringLiteral("颜色标准对话框实例"));
colorFrame = new QFrame;
colorFrame->setFrameShape(QFrame::Box);
colorFrame->setAutoFillBackground(true);
fontBtn = new QPushButton;
fontBtn->setText(QStringLiteral("字体标准对话框实例"));
fontLineEdit = new QLineEdit;
fontLineEdit->setText(tr("Welcome!"));
inputBtn = new QPushButton;
inputBtn->setText(QStringLiteral("标准输入对话框实例"));
msgBtn = new QPushButton;
msgBtn->setText(QStringLiteral("标准消息对话框实例"));
CustomBtn = new QPushButton;
CustomBtn->setText(QStringLiteral("用户自定义消息对话框"));
label = new QLabel;
label->setFrameStyle(QFrame::Panel | QFrame::Sunken);
mainLayout = new QGridLayout(this);
mainLayout->addWidget(fileBtn, 0, 0);
mainLayout->addWidget(fileLineEdit, 0, 1);
mainLayout->addWidget(colorBtn, 1, 0);
mainLayout->addWidget(colorFrame, 1, 1);
mainLayout->addWidget(fontBtn, 2, 0);
mainLayout->addWidget(fontLineEdit, 2, 1);
mainLayout->addWidget(inputBtn, 3, 0);
mainLayout->addWidget(msgBtn, 3, 1);
mainLayout->addWidget(CustomBtn, 4, 0);
mainLayout->addWidget(label, 4, 1);
QObject::connect(fileBtn, SIGNAL(clicked()), this, SLOT(showFile()));
QObject::connect(colorBtn, SIGNAL(clicked()), this, SLOT(showColor()));
QObject::connect(fontBtn, SIGNAL(clicked()), this, SLOT(showFont()));
QObject::connect(inputBtn, SIGNAL(clicked()), this, SLOT(showInputDlg()));
QObject::connect(msgBtn, SIGNAL(clicked()), this, SLOT(showMsgDlg()));
QObject::connect(CustomBtn, SIGNAL(clicked()), this, SLOT(showCustomDlg()));
}
void Dialog::showFile()
{
QString s = QFileDialog::getOpenFileName(this, "open file dialog", "/", tr("files (*.cpp *.c *.h)"));
fileLineEdit->setText(s);
}
void Dialog::showColor()
{
QColor c = QColorDialog::getColor(Qt::blue);
if(c.isValid())
{
colorFrame->setPalette(QPalette(c));
}
}
void Dialog::showFont()
{
bool ok;
QFont f = QFontDialog::getFont(&ok);
if(ok)
{
fontLineEdit->setFont(f);
}
}
void Dialog::showInputDlg()
{
inputDlg = new InputDlg;
inputDlg->show();
}
void Dialog::showMsgDlg()
{
msgDlg = new MsgBoxDlg();
msgDlg->show();
}
void Dialog::showCustomDlg()
{
label->setText(tr("Custom Message Box"));
QMessageBox customMsgBox;
customMsgBox.setWindowTitle(QStringLiteral("用户自定义消息框"));
QPushButton *yesBtn = customMsgBox.addButton(tr("yes"), QMessageBox::ActionRole);
QPushButton *noBtn = customMsgBox.addButton(tr("No"), QMessageBox::ActionRole);
QPushButton *cancelBtn = customMsgBox.addButton(QMessageBox::Cancel);
customMsgBox.setText(QStringLiteral("这是一个用户自定义消息框"));
customMsgBox.setIconPixmap(QPixmap("Qt.png"));
customMsgBox.exec();
if(customMsgBox.clickedButton() == yesBtn)
label->setText("Custom Message Box/Yes");
if(customMsgBox.clickedButton() == noBtn)
label->setText("Custom Message Box/No");
if(customMsgBox.clickedButton() == cancelBtn)
label->setText("Custom Message Box/Cancel");
}
Dialog::~Dialog()
{
}