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_QLabelclass, inherited from the frameworkQLabelclass, 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 QDialogclass, 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_QLabelobject, and display the appropriate results in the dialog.
- Instantiate this dialog under the QApplicationobject, and execute.
- Create the project file to build a widget...
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
        