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
|
#ifndef GUIDEMO_H
#define GUIDEMO_H
#include <QWidget>
class
QLabel;
class
QLineEdit;
class
QPushButton;
class
GUIDemo :
public
QWidget {
Q_OBJECT
public
:
GUIDemo(QWidget *parent = 0);
private
:
QLabel *display;
QLineEdit *inputField;
QLineEdit *outputField;
QPushButton *newButton;
QPushButton *loadButton;
QPushButton *saveButton;
QPushButton *encodeButton;
QPushButton *decodeButton;
QPushButton *clearButton;
QPushButton *copyButton;
};
#endif
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:GUIDemo.h
功能:示範 C++ 程式
作者:張凱慶
時間:西元 2012 年 10 月 */
|
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
|
#include <QtGui>
#include "GUIDemo.h"
GUIDemo::GUIDemo(QWidget *parent) : QWidget(parent) {
QLabel *input =
new
QLabel(tr(
"Input:"
));
QLabel *output =
new
QLabel(tr(
"Output:"
));
display =
new
QLabel(tr(
"something happened"
));
inputField =
new
QLineEdit;
outputField =
new
QLineEdit;
outputField->setReadOnly(
true
);
newButton =
new
QPushButton(tr(
"New"
));
loadButton =
new
QPushButton(tr(
"Load"
));
saveButton =
new
QPushButton(tr(
"Save"
));
encodeButton =
new
QPushButton(tr(
"Encode"
));
decodeButton =
new
QPushButton(tr(
"Decode"
));
clearButton =
new
QPushButton(tr(
"Clear"
));
copyButton =
new
QPushButton(tr(
"Copy"
));
QGridLayout *layout =
new
QGridLayout;
layout->addWidget(input, 0, 0);
layout->addWidget(inputField, 0, 1, 1, 6, 0);
layout->addWidget(output, 1, 0);
layout->addWidget(outputField, 1, 1, 1, 6, 0);
layout->addWidget(newButton, 2, 0);
layout->addWidget(loadButton, 2, 1);
layout->addWidget(saveButton, 2, 2);
layout->addWidget(encodeButton, 2, 3);
layout->addWidget(decodeButton, 2, 4);
layout->addWidget(clearButton, 2, 5);
layout->addWidget(copyButton, 2, 6);
layout->addWidget(display, 3, 0, 1, 7, 0);
setLayout(layout);
setWindowTitle(tr(
"GUIDemo"
));
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:GUIDemo.cpp
功能:示範 C++ 程式
作者:張凱慶
時間:西元 2012 年 10 月 */
|
11
|
outputField->setReadOnly(
true
);
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
layout->addWidget(input, 0, 0);
layout->addWidget(inputField, 0, 1, 1, 6);
layout->addWidget(output, 1, 0);
layout->addWidget(outputField, 1, 1, 1, 6);
layout->addWidget(newButton, 2, 0);
layout->addWidget(loadButton, 2, 1);
layout->addWidget(saveButton, 2, 2);
layout->addWidget(encodeButton, 2, 3);
layout->addWidget(decodeButton, 2, 4);
layout->addWidget(clearButton, 2, 5);
layout->addWidget(copyButton, 2, 6);
layout->addWidget(display, 3, 0, 1, 7);
|
37
|
layout->addWidget(display, 3, 0, 1, 7);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include <QtGui>
#include "GUIDemo.h"
int
main(
int
argv,
char
**args)
{
QApplication app(argv, args);
GUIDemo demo;
demo.show();
return
app.exec();
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:main.cpp
功能:示範 C++ 程式
作者:張凱慶
時間:西元 2012 年 10 月 */
|