Вы находитесь на странице: 1из 75

1

,


(QT-Designer).
.

, ,

,

I.

(GUI)
,
(, , , , ..).
GUI-
,
.


,
().
(Widget = Window - + Gadget ) - ,
.



QT Library

,

.

(Label) ,

, QT Library


(ProgressBar)
, , -
(LCDNumber)


.

,
(
)


(LineEdit) .

(),

()

(TextEdit)

10

(SpinBox
DoubleSpinBox)

.


(DateEdit,
TimeEdit
DateTimeEdit).

11

12

(ListWidget)

.

(ComboBox).

(TableWidget)

.
(TreeWidget) -

(, ).

(PushButton ) . , - -.
(CheckBox)
.
, , .

(RadioButton)

(.
13 ).


14

SpinBox
DoubleSpinBox
LineEdit
TextEdit
DateEdit
TimeEdit
DateTimeEdit
CheckBox
ComboBox, ListWidget,
RadioButton
ListWidget,
CheckBox

15

2-5 ,

, .
,

(2-8) ;

( 8) .


:
a) ;
b) ;
c) (, , webmoney ..)

16

a) , 2 ;
b) ,
;
c) , .
17

18



.

,
(, ).
, ,

(, , ..).

19

(GroupBox)

.
(TabWidget)
,
. , .
(StackedWidget)
,
,
.

20


, .

.

21



.



.

1) QT Application
2)
3)
()

4)
5) ,

22

II.

1) QT Application
2) QMainWindow
3) ,

4)
23

QT Application

24


QMainWindow

25

26

27

28

29


, .
,
.


Tab ( ) Shift+Tab (
).

30

,
,

,

31

/

.

-
.
QT Library
(layout).

(VBoxLayout)

(GridLayout)

32

(HBoxLayout)


(SpacerItem)

:
,
Close Help
33

34

III.
GUI.

35

,
QMainWindow.
:

, , ;

,
;

,
.


class PrimitiveCalc : public QMainWindow
{
Q_OBJECT
public:
//
PrimitiveCalc(QWidget *parent=0,Qt::WFlags flags=0);
~PrimitiveCalc();
private:
// ,
Ui::PrimitiveCalcClass ui;
//
......
private slots:
// , .. ,
//
......
36 };

37

,
, .
ui
:
ui.< >
< >



3
SpinBox:
LValueBox
RValueBox
ResultBox

38


3 SpinBox:
LValueBox
: QDoubleSpinBox
RValueBox
ResultBox
: PrimitiveCalc
:

ui : UI::PrimitiveCalcClass
:

LValueBox
RValueBox
ResultBox
,

39

40

ui.< >
,
:
, ,
LValueBox

QDoubleSpinBox
ui.LValueBox
QDoubleSpinBox *


LValueBox
QDoubleSpinBox.
QDoubleSpinBox () :
double value() - , ;
void setValue(double value) .
, LValueBox . ,
, .
41


//
double value;
//
value = ui.LValueBox->value();
//
ui.LValueBox->setValue(value + 1);

// :
ui.LValueBox->setValue(ui.LValueBox->value() + 1);
42


LValueBox
RValueBox QDoubleSpinBox,
, ResultBox .
QDoubleSpinBox () :
double value() - , ;
void setValue(double value)
.
add
PrimitiveCalc, ResultBox
43 LValueBox RValueBox.


//
void PrimitiveCalc::add()
{
double LValue, RValue;

//

//
LValue = ui.LValueBox->value();
RValue = ui.RValueBox->value();
//
//
ui.ResultBox->setValue(LValue + RValue);
}
44

45

.
QT Library
:
Q, , QDoubleSpinBox.
, , ,
#include <QDoubleSpinBox>


QDoubleSpinBox
Properties
maximum : double
singleStep : double
minimum : double
value : double
Public Functions /
QSpinBox ( QWidget * parent = 0 )
QString cleanText () const
void setRange ( double minimum, double maximum )
void setSingleStep ( double val )
double singleStep () const
double value () const
Public Slots -
void setValue ( double val )
46

GUI-

47


( ).

, ..
,
.

,
.

48

,
, .

.
,
(QPushButton) toggled.

49


, ,
( . slot - ).
, void, .

, .
.

connect,
Qt:

bool connect(<
>, SIGNAL(< >),
< >,
SLOT(< >));

50

connect
(
).

51

< > -
,

< > , . this, .


,


(QTableWidget)
, ,

void currentCellChanged (
int currentRow, int currentColumn,
int previousRow, int previousColumn )
previousRow previousColumn
,
52

currentRow, currentColumn -
,



mainTable
MyWindow
void selection_changed(int
currentRow, int currentColumn, int
previousRow);

MyWindow
53


//
MyWindow::MyWindow()
...
{
....
connect(ui.mainTable,
SIGNAL(currentCellChanged(int, int, int, int)),
this, SLOT(selection_changed(int, int, int)));
}

54

55

, ,
.
. ( ).

, .

56


slots.
.
,
, .
() .



, ().
clicked,
, , :
void clicked (bool checked = false)

57

,
.


//
class PrimitiveCalc : public QMainWindow
...
{
...
private slots:
//:
void on_addition();
//
void on_subtraction();//
void on_product();
// .
void on_division();
//
void on_recovery();
//
//
58 };

59

btnAddition clicked()

this

on_addition()

btnSubtractionclicked()

this

on_subtraction()

clicked()

this

on_product()

btnDivision clicked()

this

on_division()

btnRecovery clicked()

this

on_recovery()

btnProduct

60

//
PrimitiveCalc::PrimitiveCalc(QWidget *parent,
Qt::WFlags flags)
: QMainWindow(parent, flags)
{
//
// ,
ui.setupUi(this);
//
connect(ui.btnAddition,SIGNAL(clicked()),this,
SLOT(on_addition()));
connect(ui.btnSubtraction,SIGNAL(clicked()),
this, SLOT(on_subtraction()));
.....
61 }


(QTableWidget)
, ,

void currentCellChanged (
int currentRow, int currentColumn,
int previousRow, int previousColumn )
previousRow previousColumn
,
62

currentRow, currentColumn -
,


MyWindow
selection_changed(),
, ,
,
.
table.
checkDown.

63

/

void setChecked ( bool )


//
class MyWindow : public QMainWindow
{
...
private slots:
//
void selection_changed(int currentRow, int
currentColumn, int previousRow);
};

64


//
MyWindow::MyWindow()
...
{
....
connect(ui.table,
SIGNAL(currentCellChanged(int, int, int, int)),
this, SLOT(selection_changed(int, int, int)));
}

65


//
void MyWindow::selection_changed(int currentRow,
int currentColumn, int previousRow)
{
bool isDown;
//
isDown = currentRow > previousRow;
ui.checkDown->setChecked(isRight);
}
66

67

.


signals.

().

68

( void).


,
emit

//
class MyWindow : public QMainWindow
{
...
public signals:
// , .
//
void create(bool);
private:
int *mass;
int count;
};
69

//
//

//
MyWindow::MyWindow(QWidget *parent,Qt::WFlags flags)
: QMainWindow(parent, flags)
{
//
mass = (int *)malloc(1000*sizeof(int));
count = 1000;
//
emit create(mass != NULL);
}

70

ui,
;

,
.

71

,
.

72

on_, ..
, on_< >_< >

;

,
() ;

73

,

;

, ,
,

;

, ,
connect true,
connect

, ,

74

,
;
.


, , currentCellChanged
:

75


;

(
setCurrentRow).