Слайд 1QT
Week 12
Signals and Slots
Layouts
Слайд 2Signals and Slots
Signal – send specific signal to a slot
after a specific action is done(ex: button pressed() or released)
Slot
– what must be done after signal is received(ex: close() an application or change the color of label)
Слайд 3Syntax of Signal and Slot
QObject::connect(button,SIGNAL(clicked()),&application, SLOT(close()));
QObject is needed to create
a macro. Must be used when signal and slot are
used
connect() – function is needed to create a macro
button – object for signal
SIGNAL(clicked()) – what action must be done when function of object for signal is done
&application – object for slot
SLOT(close()) – what action must be done with object for slot
Слайд 4Layout types
There are 2 types of layout in QT
Layouts
Absolute positioning
Слайд 5Absolute Positioning
The programmer specifies the position and the size of
each widget in pixels. When you use absolute positioning, you
have to understand several things:
the size and the position of a widget do not change, if you resize a window
applications look different (often crappy) on various platforms
- changing fonts in your application might spoil the layout
- if you decide to change your layout, you must completely redo your layout, which is tedious and time consuming
Слайд 6Example
Function setGeometry(x,y,w,h)
x – begin coordinate of x-axis
y – begin coordinate
of y-axis
w – width of object
h – height of object
Ex:
button->setGeometry(100,0,50,50)
Слайд 7Layouts
QHBoxLayout – places objects in horizontal way
QVBoxLayout – places objects
in vertical way
QGridLayout – places objects like a grid
Ex: grid->addWidget(button, i, j);