In this chapter you looked at various aspects of widgets. You learned about event processing and the roles of signals and slots in widget design. You also saw how to paint a custom widget and manage child widgets.
QWidget handles window system events by calling virtual methods. You reimplement these methods to process the events. Each method receives a class containing information about the event as an argument.
Signals are used to notify other widgets or other parts of the application that the state of the widget has changed. Slots are used to change the state of the widget. They can be connected to signals or invoked directly (because they are methods). A widget's signals and slots should be documented in the header file.
You should paint your widget only inside the paintEvent() method. This is easy to do if you save the state of your widget as private or protected data and paint the widget to reflect that state. You can then change the state in any other method and call update() to generate a paint event and update the widget. Drawing is done with QPainter.
Child widgets need to be properly placed on their parent if the parent widget is to be attractive and in the standard style. You can easily and properly place child widgets by using one of the geometry managers provided by Qt: QBoxLayout or QGridLayout.