Qt event model with signals/slots/MOC – an example
In this section, we will create an application to handle mouse events in QLabel
. We will override the mouse events in a custom QLabel
and handle them in the dialog where the custom label is placed. The approach to this application is as follows:
- Create a custom
my_QLabel
class, inherited from the frameworkQLabel
class, and override the mouse events, such as mouse-move, mouse-pressed, and mouse-leave. - Define the signals that correspond to these events in
my_QLabel
, and emit them from the corresponding event handlers. - Create a dialog class inherited from the
QDialog
class, and handcode the positions and layouts of all of the widgets, including the custom widget created to handle mouse events. - In the dialog class, define the slots to handle the emitted signals from the
my_QLabel
object, and display the appropriate results in the dialog. - Instantiate this dialog under the
QApplication
object, and execute. - Create the project file to build a widget...