forked from GLDsuh-a/qt-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputdlg.cpp
More file actions
105 lines (87 loc) · 3.53 KB
/
inputdlg.cpp
File metadata and controls
105 lines (87 loc) · 3.53 KB
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
#include "inputdlg.h"
#include <QInputDialog>
InputDlg::InputDlg(QWidget *parent) :
QDialog(parent)
{
setWindowTitle(QStringLiteral("标准输入对话框的实例"));
nameLabel1 =new QLabel;
nameLabel1->setText(QStringLiteral("名字:"));
nameLabel2 =new QLabel;
nameLabel2->setText(QStringLiteral("张三")); //姓名的初始值
nameLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
nameBtn =new QPushButton;
nameBtn->setText(QStringLiteral("修改姓名"));
sexLabel1 =new QLabel;
sexLabel1->setText(QStringLiteral("性别:"));
sexLabel2 =new QLabel;
sexLabel2->setText(QStringLiteral("男")); //性别的初始值
sexLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
sexBtn =new QPushButton;
sexBtn->setText(QStringLiteral("修改性别"));
ageLabel1 =new QLabel;
ageLabel1->setText(QStringLiteral("年龄:"));
ageLabel2 =new QLabel;
ageLabel2->setText(QStringLiteral("21")); //年龄的初始值
ageLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
ageBtn =new QPushButton;
ageBtn->setText(QStringLiteral("修改年龄"));
scoreLabel1 =new QLabel;
scoreLabel1->setText(QStringLiteral("成绩:"));
scoreLabel2 =new QLabel;
scoreLabel2->setText(QStringLiteral("80")); //成绩的初始值
scoreLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
scoreBtn =new QPushButton;
scoreBtn->setText(QStringLiteral("修改成绩"));
mainLayout =new QGridLayout(this);
mainLayout->addWidget(nameLabel1,0,0);
mainLayout->addWidget(nameLabel2,0,1);
mainLayout->addWidget(nameBtn,0,2);
mainLayout->addWidget(sexLabel1,1,0);
mainLayout->addWidget(sexLabel2,1,1);
mainLayout->addWidget(sexBtn,1,2);
mainLayout->addWidget(ageLabel1,2,0);
mainLayout->addWidget(ageLabel2,2,1);
mainLayout->addWidget(ageBtn,2,2);
mainLayout->addWidget(scoreLabel1,3,0);
mainLayout->addWidget(scoreLabel2,3,1);
mainLayout->addWidget(scoreBtn,3,2);
mainLayout->setMargin(15);
mainLayout->setSpacing(10);
connect(nameBtn,SIGNAL(clicked()),this,SLOT(ChangeName()));
connect(sexBtn,SIGNAL(clicked()),this,SLOT(ChangeSex()));
connect(ageBtn,SIGNAL(clicked()),this,SLOT(ChangeAge()));
connect(scoreBtn,SIGNAL(clicked()),this,SLOT(ChangeScore()));
}
void InputDlg::ChangeName()
{
bool ok;
QString text=QInputDialog::getText(this,QStringLiteral("标准字符串输入对话框"),QStringLiteral("请输入姓名:"), QLineEdit::Normal,nameLabel2->text(),&ok);
if (ok && !text.isEmpty())
nameLabel2->setText(text);
}
void InputDlg::ChangeSex()
{
QStringList SexItems;
SexItems << QStringLiteral("man") << QStringLiteral("woman");
bool ok;
QString SexItem = QInputDialog::getItem(this, QStringLiteral("strandard item select frame"),
QStringLiteral("please select sex:"), SexItems, 0, false, &ok);
if (ok && !SexItem.isEmpty())
sexLabel2->setText(SexItem);
}
void InputDlg::ChangeAge()
{
bool ok;
int age = QInputDialog::getInt(this, QStringLiteral("strandard int input frame"),
QStringLiteral("please inpute age"), ageLabel2->text().toInt(&ok), 0, 100, 1, &ok);
if (ok)
ageLabel2->setText(QString(QStringLiteral("%1")).arg(age));
}
void InputDlg::ChangeScore()
{
bool ok;
double score = QInputDialog::getDouble(this, QStringLiteral("strandard double input frame"),
QStringLiteral("please input score:"),scoreLabel2->text().toDouble(&ok), 0, 100, 1, &ok);
if(ok)
scoreLabel2->setText(QString(QStringLiteral("%1")).arg(score));
}