1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/buttongroups/buttongroups.doc:4 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>Buttons and Groupboxes</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Buttons and Groupboxes</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 | <p>
|
---|
36 | This example shows different types of groupboxes (buttongroups, etc.) and
|
---|
37 | different kinds of buttons (checkboxes, radiobuttons, pushbuttons, etc.).
|
---|
38 | <p> <hr>
|
---|
39 | <p> Header file:
|
---|
40 | <p> <pre>/****************************************************************************
|
---|
41 | ** $Id: buttongroups-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
42 | **
|
---|
43 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
44 | **
|
---|
45 | ** This file is part of an example program for Qt. This example
|
---|
46 | ** program may be used, distributed and modified without limitation.
|
---|
47 | **
|
---|
48 | *****************************************************************************/
|
---|
49 |
|
---|
50 | #ifndef BUTTONS_GROUPS_H
|
---|
51 | #define BUTTONS_GROUPS_H
|
---|
52 |
|
---|
53 | #include <<a href="qwidget-h.html">qwidget.h</a>>
|
---|
54 |
|
---|
55 | class QCheckBox;
|
---|
56 | class QRadioButton;
|
---|
57 |
|
---|
58 | class ButtonsGroups : public <a href="qwidget.html">QWidget</a>
|
---|
59 | {
|
---|
60 | <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
|
---|
61 |
|
---|
62 | public:
|
---|
63 | ButtonsGroups( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0 );
|
---|
64 |
|
---|
65 | protected:
|
---|
66 | <a href="qcheckbox.html">QCheckBox</a> *state;
|
---|
67 | <a href="qradiobutton.html">QRadioButton</a> *rb21, *rb22, *rb23;
|
---|
68 |
|
---|
69 | protected slots:
|
---|
70 | void slotChangeGrp3State();
|
---|
71 |
|
---|
72 | };
|
---|
73 |
|
---|
74 | #endif
|
---|
75 | </pre>
|
---|
76 |
|
---|
77 | <p> <hr>
|
---|
78 | <p> Implementation:
|
---|
79 | <p> <pre>/****************************************************************************
|
---|
80 | ** $Id: buttongroups-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
81 | **
|
---|
82 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
83 | **
|
---|
84 | ** This file is part of an example program for Qt. This example
|
---|
85 | ** program may be used, distributed and modified without limitation.
|
---|
86 | **
|
---|
87 | *****************************************************************************/
|
---|
88 |
|
---|
89 | #include "buttongroups.h"
|
---|
90 |
|
---|
91 | #include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>>
|
---|
92 | #include <<a href="qbuttongroup-h.html">qbuttongroup.h</a>>
|
---|
93 | #include <<a href="qlayout-h.html">qlayout.h</a>>
|
---|
94 | #include <<a href="qradiobutton-h.html">qradiobutton.h</a>>
|
---|
95 | #include <<a href="qcheckbox-h.html">qcheckbox.h</a>>
|
---|
96 | #include <<a href="qgroupbox-h.html">qgroupbox.h</a>>
|
---|
97 | #include <<a href="qpushbutton-h.html">qpushbutton.h</a>>
|
---|
98 |
|
---|
99 | /*
|
---|
100 | * Constructor
|
---|
101 | *
|
---|
102 | * Creates all child widgets of the ButtonGroups window
|
---|
103 | */
|
---|
104 |
|
---|
105 | <a name="f261"></a>ButtonsGroups::ButtonsGroups( <a href="qwidget.html">QWidget</a> *parent, const char *name )
|
---|
106 | : <a href="qwidget.html">QWidget</a>( parent, name )
|
---|
107 | {
|
---|
108 | // Create Widgets which allow easy layouting
|
---|
109 | <a href="qvboxlayout.html">QVBoxLayout</a> *vbox = new <a href="qvboxlayout.html">QVBoxLayout</a>( this, 11, 6 );
|
---|
110 | <a href="qhboxlayout.html">QHBoxLayout</a> *box1 = new <a href="qhboxlayout.html">QHBoxLayout</a>( vbox );
|
---|
111 | <a href="qhboxlayout.html">QHBoxLayout</a> *box2 = new <a href="qhboxlayout.html">QHBoxLayout</a>( vbox );
|
---|
112 |
|
---|
113 | // ------- first group
|
---|
114 |
|
---|
115 | // Create an exclusive button group
|
---|
116 | <a href="qbuttongroup.html">QButtonGroup</a> *bgrp1 = new <a href="qbuttongroup.html">QButtonGroup</a>( 1, QGroupBox::Horizontal, "Button Group 1 (exclusive)", this);
|
---|
117 | box1-><a href="qboxlayout.html#addWidget">addWidget</a>( bgrp1 );
|
---|
118 | <a name="x549"></a> bgrp1-><a href="qbuttongroup.html#setExclusive">setExclusive</a>( TRUE );
|
---|
119 |
|
---|
120 | // insert 3 radiobuttons
|
---|
121 | <a href="qradiobutton.html">QRadioButton</a> *rb11 = new <a href="qradiobutton.html">QRadioButton</a>( "&Radiobutton 1", bgrp1 );
|
---|
122 | <a name="x559"></a> rb11-><a href="qradiobutton.html#setChecked">setChecked</a>( TRUE );
|
---|
123 | (void)new <a href="qradiobutton.html">QRadioButton</a>( "R&adiobutton 2", bgrp1 );
|
---|
124 | (void)new <a href="qradiobutton.html">QRadioButton</a>( "Ra&diobutton 3", bgrp1 );
|
---|
125 |
|
---|
126 | // ------- second group
|
---|
127 |
|
---|
128 | // Create a non-exclusive buttongroup
|
---|
129 | <a href="qbuttongroup.html">QButtonGroup</a> *bgrp2 = new <a href="qbuttongroup.html">QButtonGroup</a>( 1, QGroupBox::Horizontal, "Button Group 2 (non-exclusive)", this );
|
---|
130 | box1-><a href="qboxlayout.html#addWidget">addWidget</a>( bgrp2 );
|
---|
131 | bgrp2-><a href="qbuttongroup.html#setExclusive">setExclusive</a>( FALSE );
|
---|
132 |
|
---|
133 | // insert 3 checkboxes
|
---|
134 | (void)new <a href="qcheckbox.html">QCheckBox</a>( "&Checkbox 1", bgrp2 );
|
---|
135 | <a href="qcheckbox.html">QCheckBox</a> *cb12 = new <a href="qcheckbox.html">QCheckBox</a>( "C&heckbox 2", bgrp2 );
|
---|
136 | <a name="x552"></a> cb12-><a href="qcheckbox.html#setChecked">setChecked</a>( TRUE );
|
---|
137 | <a href="qcheckbox.html">QCheckBox</a> *cb13 = new <a href="qcheckbox.html">QCheckBox</a>( "Triple &State Button", bgrp2 );
|
---|
138 | <a name="x553"></a> cb13-><a href="qcheckbox.html#setTristate">setTristate</a>( TRUE );
|
---|
139 | cb13-><a href="qcheckbox.html#setChecked">setChecked</a>( TRUE );
|
---|
140 |
|
---|
141 | // ------------ third group
|
---|
142 |
|
---|
143 | // create a buttongroup which is exclusive for radiobuttons and non-exclusive for all other buttons
|
---|
144 | <a href="qbuttongroup.html">QButtonGroup</a> *bgrp3 = new <a href="qbuttongroup.html">QButtonGroup</a>( 1, QGroupBox::Horizontal, "Button Group 3 (Radiobutton-exclusive)", this );
|
---|
145 | box2-><a href="qboxlayout.html#addWidget">addWidget</a>( bgrp3 );
|
---|
146 | <a name="x550"></a> bgrp3-><a href="qbuttongroup.html#setRadioButtonExclusive">setRadioButtonExclusive</a>( TRUE );
|
---|
147 |
|
---|
148 | // insert three radiobuttons
|
---|
149 | rb21 = new <a href="qradiobutton.html">QRadioButton</a>( "Rad&iobutton 1", bgrp3 );
|
---|
150 | rb22 = new <a href="qradiobutton.html">QRadioButton</a>( "Radi&obutton 2", bgrp3 );
|
---|
151 | rb23 = new <a href="qradiobutton.html">QRadioButton</a>( "Radio&button 3", bgrp3 );
|
---|
152 | rb23-><a href="qradiobutton.html#setChecked">setChecked</a>( TRUE );
|
---|
153 |
|
---|
154 | // insert a checkbox...
|
---|
155 | state = new <a href="qcheckbox.html">QCheckBox</a>( "E&nable Radiobuttons", bgrp3 );
|
---|
156 | state-><a href="qcheckbox.html#setChecked">setChecked</a>( TRUE );
|
---|
157 | // ...and connect its SIGNAL clicked() with the SLOT slotChangeGrp3State()
|
---|
158 | <a href="qobject.html#connect">connect</a>( state, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( slotChangeGrp3State() ) );
|
---|
159 |
|
---|
160 | // ------------ fourth group
|
---|
161 |
|
---|
162 | // create a groupbox which layouts its childs in a columns
|
---|
163 | <a href="qgroupbox.html">QGroupBox</a> *bgrp4 = new <a href="qbuttongroup.html">QButtonGroup</a>( 1, QGroupBox::Horizontal, "Groupbox with normal buttons", this );
|
---|
164 | box2-><a href="qboxlayout.html#addWidget">addWidget</a>( bgrp4 );
|
---|
165 |
|
---|
166 | // insert four pushbuttons...
|
---|
167 | (void)new <a href="qpushbutton.html">QPushButton</a>( "&Push Button", bgrp4, "push" );
|
---|
168 |
|
---|
169 | // now make the second one a toggle button
|
---|
170 | <a href="qpushbutton.html">QPushButton</a> *tb2 = new <a href="qpushbutton.html">QPushButton</a>( "&Toggle Button", bgrp4, "toggle" );
|
---|
171 | <a name="x558"></a> tb2-><a href="qpushbutton.html#setToggleButton">setToggleButton</a>( TRUE );
|
---|
172 | <a name="x556"></a> tb2-><a href="qpushbutton.html#setOn">setOn</a>( TRUE );
|
---|
173 |
|
---|
174 | // ... and make the third one a flat button
|
---|
175 | <a href="qpushbutton.html">QPushButton</a> *tb3 = new <a href="qpushbutton.html">QPushButton</a>( "&Flat Button", bgrp4, "flat" );
|
---|
176 | <a name="x555"></a> tb3-><a href="qpushbutton.html#setFlat">setFlat</a>(TRUE);
|
---|
177 |
|
---|
178 | // .. and the fourth a button with a menu
|
---|
179 | <a href="qpushbutton.html">QPushButton</a> *tb4 = new <a href="qpushbutton.html">QPushButton</a>( "Popup Button", bgrp4, "popup" );
|
---|
180 | <a href="qpopupmenu.html">QPopupMenu</a> *menu = new <a href="qpopupmenu.html">QPopupMenu</a>(tb4);
|
---|
181 | menu-><a href="qmenudata.html#insertItem">insertItem</a>("Item1", 0);
|
---|
182 | menu-><a href="qmenudata.html#insertItem">insertItem</a>("Item2", 1);
|
---|
183 | menu-><a href="qmenudata.html#insertItem">insertItem</a>("Item3", 2);
|
---|
184 | menu-><a href="qmenudata.html#insertItem">insertItem</a>("Item4", 3);
|
---|
185 | <a name="x557"></a> tb4-><a href="qpushbutton.html#setPopup">setPopup</a>(menu);
|
---|
186 | }
|
---|
187 |
|
---|
188 | /*
|
---|
189 | * SLOT slotChangeGrp3State()
|
---|
190 | *
|
---|
191 | * enables/disables the radiobuttons of the third buttongroup
|
---|
192 | */
|
---|
193 |
|
---|
194 | void <a name="f262"></a>ButtonsGroups::slotChangeGrp3State()
|
---|
195 | {
|
---|
196 | <a name="x560"></a><a name="x551"></a> rb21-><a href="qwidget.html#setEnabled">setEnabled</a>( state-><a href="qcheckbox.html#isChecked">isChecked</a>() );
|
---|
197 | rb22-><a href="qwidget.html#setEnabled">setEnabled</a>( state-><a href="qcheckbox.html#isChecked">isChecked</a>() );
|
---|
198 | rb23-><a href="qwidget.html#setEnabled">setEnabled</a>( state-><a href="qcheckbox.html#isChecked">isChecked</a>() );
|
---|
199 | }
|
---|
200 | </pre>
|
---|
201 |
|
---|
202 | <p> <hr>
|
---|
203 | <p> Main:
|
---|
204 | <pre>/****************************************************************************
|
---|
205 | ** $Id: buttongroups-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
206 | **
|
---|
207 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
208 | **
|
---|
209 | ** This file is part of an example program for Qt. This example
|
---|
210 | ** program may be used, distributed and modified without limitation.
|
---|
211 | **
|
---|
212 | *****************************************************************************/
|
---|
213 |
|
---|
214 | #include "buttongroups.h"
|
---|
215 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
216 |
|
---|
217 | int main( int argc, char **argv )
|
---|
218 | {
|
---|
219 | <a href="qapplication.html">QApplication</a> a( argc, argv );
|
---|
220 |
|
---|
221 | ButtonsGroups buttonsgroups;
|
---|
222 | buttonsgroups.<a href="qwidget.html#resize">resize</a>( 500, 250 );
|
---|
223 | buttonsgroups.<a href="qwidget.html#setCaption">setCaption</a>( "Qt Example - Buttongroups" );
|
---|
224 | a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &buttonsgroups );
|
---|
225 | buttonsgroups.<a href="qwidget.html#show">show</a>();
|
---|
226 |
|
---|
227 | return a.<a href="qapplication.html#exec">exec</a>();
|
---|
228 | }
|
---|
229 | </pre>
|
---|
230 |
|
---|
231 | <p>See also <a href="examples.html">Examples</a>.
|
---|
232 |
|
---|
233 | <!-- eof -->
|
---|
234 | <p><address><hr><div align=center>
|
---|
235 | <table width=100% cellspacing=0 border=0><tr>
|
---|
236 | <td>Copyright © 2007
|
---|
237 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
238 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
239 | </table></div></address></body>
|
---|
240 | </html>
|
---|