Pushbutton, radiobutton, and checkbox control
Http://book.51cto.com/art/201203/323282.htm
3. Example implementation
Here we use the slot function automatically generated by QT creator, without the need to write the ing between signals and slot functions. (QT creator automatically generates a slot function: Right-click the control → go to slot, and select the corresponding signal function of the slot function, after confirmation, the slot function declaration and definition framework will be generated .)
| |
| Figure 3-14 select a signal |
Right-click the radiobutton control, select the go to slot option, and select the signal in the signal window, as shown in Figure 3-14. In this example, we use the clicked () signal. After confirmation, it will jump to the definition framework of the slot function. The slot function declaration has been automatically generated, which is similar to winform. Then you only need to fill in the slot function.
Add slots for controls radiobutton_2, radiobutton_3, checkbox, checkbox_2, checkbox_3, btn_radiobutton, and btn_checkbox in the same way.
After the project is created and the corresponding control properties, signals, and slot functions are compiled, edit the corresponding file.
Mainwindow. H (bold in the text indicates the content to be added ):
- # Ifndef mainwindow_h
- # Define mainwindow_h
- # Include <qmainwindow>
- Namespace UI {
- Class mainwindow;
- }
- Class mainwindow: Public qmainwindow
- {
- Q_object
- Public:
- Explicit mainwindow (qwidget * parent = 0 );
- ~ Mainwindow ();
- Void displaycheckbox ();
- PRIVATE:
- Ui: mainwindow * UI;
- Private slots: // slot function, automatically added
- Void on_checkbox_3_clicked ();
- Void on_checkbox_2_clicked ();
- Void on_checkbox_clicked ();
- Void on_radiobutton_3_clicked ();
- Void on_radiobutton_2_clicked ();
- Void on_radiobutton_clicked ();
- Void on_btn_checkbox_clicked ();
- Void on_btn_radiobutton_clicked ();
- };
- # Endif // mainwindow_h