Download presentation
Presentation is loading. Please wait.
Published byDamon Garrison Modified over 9 years ago
1
GUIs Basic Concepts
2
GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components
3
QT QT – layer of code to enable platform independent applications
4
QT Must add QT += widgets to.pro file – Tells QTCreator to look for those.h files / libraries
5
QT QApplication : class that manages resources, runs event loop – Create BEFORE anything GUI related – exec starts loop Last thing main does returns when all windows closed
6
QObject All GUI components are QObjects
7
Most Important Widgets Display text : Qlabel Text input : QLineEdit Button : QPushButton
8
Making a Window Any Qwidget can be a window – Call show method
9
Styling Can modify style through code:
10
Styling Can style with HTML within strings:
11
Styling Can apply style sheets to widgets
12
Event Handling & Layout
13
Event Based Programming Event : anything that happens – Window resized – Button pressed – Network connection closes
14
Event Based Programming Event : anything that happens – Window resized – Button pressed – Network connection closes Event based programs: – Enter infinite loop – Wait for events to happen – respond to them
15
Notifications Callback : – Way to register a function to be called in certain situation
16
Notifications Callback : – Way to register a function to be called in certain situation Function Pointer : stores address of a function – Type depends on return type and parameters
17
Function Pointers Name of function by itself is memory address Use to set function pointers:
18
Define Compiler macro – Preprocessor definition that replaces your source code with something more complex
19
Slots & Signals In QT – Signal : a message that a Widget can send – Slot : a function that can receive a message Signals wired to 0+ slots On event, sends signal to each listening slot
20
A Working Button Want a button that quits program:
21
A Working Button Want a button that quits program: Need to hook a signal from Button To slot in application
22
A Working Button Want a button that quits program: Need to hook a signal from Button To slot in application
23
Quitting Qobject::connect function hooks signal to slot – SIGNAL / SLOT ugly macros Address of widget Function to use as SIGNAL / SLOT
24
Layout Cross platform /resizeable GUIs need to be flexible Place components in layout boxes (sizers) – Components request needed size – Let layout boxes organize components
25
A Simple QT Layout Layout widgets – Invisible boxes that group widgets QVBoxLayout : Vertical group QHBoxLayout : Horizontal group
26
In Code Make widgets Add to layout
27
Behaviors Behavior hookup:
28
Behavior Errors Hookup happens at runtime… watch for errors in Application Output – Stuff inside SLOT / SIGNAL just treated as strings!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.