QT Week 12 Signals and Slots Layouts
Signals 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)
Syntax 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
Layout types There are 2 types of layout in QT - Layouts - Absolute positioning
Absolute 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
Example Function set. Geometry(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->set. Geometry(100, 0, 50)
Layouts QHBox. Layout – places objects in horizontal way QVBox. Layout – places objects in vertical way QGrid. Layout – places objects like a grid Ex: grid->add. Widget(button, i, j);