Download presentation
Presentation is loading. Please wait.
1
Custom Widgets & Events
2
Top Level Windows Dialog Simple window Window Has status bar, menu
3
Subclasses QT GUIs generally subclass an existing class Add features
FindDialog extends QDialog Add features Controls this dialog has New behaviors (signals/slots) Connections between behaviors
4
FindDialog.h Extends Qdialog Q_OBJECT
Must add for slots and signals to get handled correctly Constructor takes optional pointer to parent widget
5
FindDialog.h signals: public/private slots:
Special section identifying signal functions public/private slots: Section identifying slot functions
6
FindDialog.h private members:
Components we may need to refer to throughout lifetime of app
7
FindDialog.cpp Constructor Body…
If parent widget we live in, pass that off to Qdialog part to handle:
8
The Main Main just creates instance of our GUI, starts app:
9
FindDialog.cpp Constructor Body… setup components Optional stuff:
tr( ) – allows for easier translation & - Defines alt-shortcut based on next char setBudy – makes hotkey for label select lineEdit
10
FindDialog.cpp Constructor Body… setup components Optional stuff:
setDefualt( ) – makes this button be one that responds to Enter key on form setEnabled(false) – make widget unusable
11
The Layout hBox for main vBox for left hBox for topLeft vBox for right
12
FindDialog.cpp Constructor Body… layout stuff
Don't need layouts to be members setFixedHeight Prevent me from messing it up sizeHint() Get preferred size
13
FindDialog.cpp Constructor Body… behavior setup
lineEdit textChanged calls our dialog's enableFindButton findButton clicked calls findClicked function of our dialog Close button closes the window Params of slot and signal should usually match though extra ones in signal may be OK
14
FindDialog.cpp Destructor
None needed!!! Qwidget destructor (part of us) deletes any contained widgets when we are deleted Would only need one for non-widget related heap allocations
15
FindDialog.cpp enableFindButton:
Slot function… must take const Qstring& because that is what lineEdit.textChanged sends:
16
FindDialog.cpp Emit function() : send with this name findClicked:
Emits appropriate signal Nothing listening, but a text editor window could…
17
QStrings QString mostly like normal string
Doesn't overload << operator though Turn QString to std::string using .toStdString()
18
Debugging Hints For console output make sure .pro has this line:
Then check application output:
19
Debugging Hints For console output make sure .pro has this line:
Or check Run in Terminal under Project settings:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.