1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Line Edits</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Line Edits</h1>
<p>
This example shows how to work with single lineedit widgets, and
how to use different echo modes and validators.
<p> <hr>
<p> Header file:
<p> <pre>/****************************************************************************
** $Id: qt/lineedits.h 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for TQt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#ifndef LINEDITS_H
#define LINEDITS_H
#include <<a href="tqgroupbox-h.html">tqgroupbox.h</a>>
class TQLineEdit;
class TQComboBox;
class LineEdits : public <a href="tqgroupbox.html">TQGroupBox</a>
{
<a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
public:
LineEdits( <a href="tqwidget.html">TQWidget</a> *parent = 0, const char *name = 0 );
protected:
<a href="tqlineedit.html">TQLineEdit</a> *lined1, *lined2, *lined3, *lined4, *lined5;
<a href="tqcombobox.html">TQComboBox</a> *combo1, *combo2, *combo3, *combo4, *combo5;
protected slots:
void slotEchoChanged( int );
void slotValidatorChanged( int );
void slotAlignmentChanged( int );
void slotInputMaskChanged( int );
void slotReadOnlyChanged( int );
};
#endif
</pre>
<p> <hr>
<p> Implementation:
<p> <pre>/****************************************************************************
** $Id: qt/lineedits.cpp 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for TQt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include "lineedits.h"
#include <<a href="tqlineedit-h.html">tqlineedit.h</a>>
#include <<a href="tqcombobox-h.html">tqcombobox.h</a>>
#include <<a href="tqframe-h.html">tqframe.h</a>>
#include <<a href="tqvalidator-h.html">tqvalidator.h</a>>
#include <<a href="tqlabel-h.html">tqlabel.h</a>>
#include <<a href="tqlayout-h.html">tqlayout.h</a>>
#include <<a href="tqhbox-h.html">tqhbox.h</a>>
/*
* Constructor
*
* Creates child widgets of the LineEdits widget
*/
<a name="f219"></a>LineEdits::LineEdits( <a href="tqwidget.html">TQWidget</a> *parent, const char *name )
: <a href="tqgroupbox.html">TQGroupBox</a>( 0, Horizontal, "Line edits", parent, name )
{
<a href="tqframe.html#setMargin">setMargin</a>( 10 );
<a href="tqvboxlayout.html">TQVBoxLayout</a>* box = new <a href="tqvboxlayout.html">TQVBoxLayout</a>( <a href="tqwidget.html#layout">layout</a>() );
<a href="tqhboxlayout.html">TQHBoxLayout</a> *row1 = new <a href="tqhboxlayout.html">TQHBoxLayout</a>( box );
<a name="x173"></a> row1-><a href="tqlayout.html#setMargin">setMargin</a>( 5 );
// Create a Label
<a href="tqlabel.html">TQLabel</a>* label = new <a href="tqlabel.html">TQLabel</a>( "Echo Mode: ", this);
<a name="x169"></a> row1-><a href="tqboxlayout.html#addWidget">addWidget</a>( label );
// Create a Combobox with three items...
combo1 = new <a href="tqcombobox.html">TQComboBox</a>( FALSE, this );
row1-><a href="tqboxlayout.html#addWidget">addWidget</a>( combo1 );
<a name="x171"></a> combo1-><a href="tqcombobox.html#insertItem">insertItem</a>( "Normal" );
combo1-><a href="tqcombobox.html#insertItem">insertItem</a>( "Password" );
combo1-><a href="tqcombobox.html#insertItem">insertItem</a>( "No Echo" );
// ...and connect the activated() TQ_SIGNAL with the slotEchoChanged() TQ_SLOT to be able
// to react when an item is selected
<a name="x170"></a> <a href="tqobject.html#connect">connect</a>( combo1, TQ_SIGNAL( <a href="tqcombobox.html#activated">activated</a>( int ) ), this, TQ_SLOT( slotEchoChanged( int ) ) );
// insert the first LineEdit
lined1 = new <a href="tqlineedit.html">TQLineEdit</a>( this );
box-><a href="tqboxlayout.html#addWidget">addWidget</a>( lined1 );
// another widget which is used for layouting
<a href="tqhboxlayout.html">TQHBoxLayout</a> *row2 = new <a href="tqhboxlayout.html">TQHBoxLayout</a>( box );
row2-><a href="tqlayout.html#setMargin">setMargin</a>( 5 );
// and the second label
label = new <a href="tqlabel.html">TQLabel</a>( "Validator: ", this );
row2-><a href="tqboxlayout.html#addWidget">addWidget</a>( label );
// A second Combobox with again three items...
combo2 = new <a href="tqcombobox.html">TQComboBox</a>( FALSE, this );
row2-><a href="tqboxlayout.html#addWidget">addWidget</a>( combo2 );
combo2-><a href="tqcombobox.html#insertItem">insertItem</a>( "No Validator" );
combo2-><a href="tqcombobox.html#insertItem">insertItem</a>( "Integer Validator" );
combo2-><a href="tqcombobox.html#insertItem">insertItem</a>( "Double Validator" );
// ...and again the activated() TQ_SIGNAL gets connected with a TQ_SLOT
<a href="tqobject.html#connect">connect</a>( combo2, TQ_SIGNAL( <a href="tqcombobox.html#activated">activated</a>( int ) ), this, TQ_SLOT( slotValidatorChanged( int ) ) );
// and the second LineEdit
lined2 = new <a href="tqlineedit.html">TQLineEdit</a>( this );
box-><a href="tqboxlayout.html#addWidget">addWidget</a>( lined2 );
// yet another widget which is used for layouting
<a href="tqhboxlayout.html">TQHBoxLayout</a> *row3 = new <a href="tqhboxlayout.html">TQHBoxLayout</a>( box );
row3-><a href="tqlayout.html#setMargin">setMargin</a>( 5 );
// we need a label for this too
label = new <a href="tqlabel.html">TQLabel</a>( "Alignment: ", this );
row3-><a href="tqboxlayout.html#addWidget">addWidget</a>( label );
// A combo box for setting alignment
combo3 = new <a href="tqcombobox.html">TQComboBox</a>( FALSE, this );
row3-><a href="tqboxlayout.html#addWidget">addWidget</a>( combo3 );
combo3-><a href="tqcombobox.html#insertItem">insertItem</a>( "Left" );
combo3-><a href="tqcombobox.html#insertItem">insertItem</a>( "Centered" );
combo3-><a href="tqcombobox.html#insertItem">insertItem</a>( "Right" );
// ...and again the activated() TQ_SIGNAL gets connected with a TQ_SLOT
<a href="tqobject.html#connect">connect</a>( combo3, TQ_SIGNAL( <a href="tqcombobox.html#activated">activated</a>( int ) ), this, TQ_SLOT( slotAlignmentChanged( int ) ) );
// and the third lineedit
lined3 = new <a href="tqlineedit.html">TQLineEdit</a>( this );
box-><a href="tqboxlayout.html#addWidget">addWidget</a>( lined3 );
// exactly the same for the fourth
<a href="tqhboxlayout.html">TQHBoxLayout</a> *row4 = new <a href="tqhboxlayout.html">TQHBoxLayout</a>( box );
row4-><a href="tqlayout.html#setMargin">setMargin</a>( 5 );
// we need a label for this too
label = new <a href="tqlabel.html">TQLabel</a>( "Input mask: ", this );
row4-><a href="tqboxlayout.html#addWidget">addWidget</a>( label );
// A combo box for choosing an input mask
combo4 = new <a href="tqcombobox.html">TQComboBox</a>( FALSE, this );
row4-><a href="tqboxlayout.html#addWidget">addWidget</a>( combo4 );
combo4-><a href="tqcombobox.html#insertItem">insertItem</a>( "No mask" );
combo4-><a href="tqcombobox.html#insertItem">insertItem</a>( "Phone number" );
combo4-><a href="tqcombobox.html#insertItem">insertItem</a>( "ISO date" );
combo4-><a href="tqcombobox.html#insertItem">insertItem</a>( "License key" );
// ...this time we use the activated( const <a href="tqstring.html">TQString</a> & ) signal
<a href="tqobject.html#connect">connect</a>( combo4, TQ_SIGNAL( <a href="tqcombobox.html#activated">activated</a>( int ) ),
this, TQ_SLOT( slotInputMaskChanged( int ) ) );
// and the fourth lineedit
lined4 = new <a href="tqlineedit.html">TQLineEdit</a>( this );
box-><a href="tqboxlayout.html#addWidget">addWidget</a>( lined4 );
// last widget used for layouting
<a href="tqhbox.html">TQHBox</a> *row5 = new <a href="tqhbox.html">TQHBox</a>( this );
box-><a href="tqboxlayout.html#addWidget">addWidget</a>( row5 );
row5-><a href="tqframe.html#setMargin">setMargin</a>( 5 );
// last label
(void)new <a href="tqlabel.html">TQLabel</a>( "Read-Only: ", row5 );
// A combo box for setting alignment
combo5 = new <a href="tqcombobox.html">TQComboBox</a>( FALSE, row5 );
combo5-><a href="tqcombobox.html#insertItem">insertItem</a>( "False" );
combo5-><a href="tqcombobox.html#insertItem">insertItem</a>( "True" );
// ...and again the activated() TQ_SIGNAL gets connected with a TQ_SLOT
<a href="tqobject.html#connect">connect</a>( combo5, TQ_SIGNAL( <a href="tqcombobox.html#activated">activated</a>( int ) ), this, TQ_SLOT( slotReadOnlyChanged( int ) ) );
// and the last lineedit
lined5 = new <a href="tqlineedit.html">TQLineEdit</a>( this );
box-><a href="tqboxlayout.html#addWidget">addWidget</a>( lined5 );
// give the first LineEdit the focus at the beginning
<a name="x181"></a> lined1-><a href="tqwidget.html#setFocus">setFocus</a>();
}
/*
* TQ_SLOT slotEchoChanged( int i )
*
* i contains the number of the item which the user has been chosen in the
* first Combobox. According to this value, we set the Echo-Mode for the
* first LineEdit.
*/
void <a name="f220"></a>LineEdits::slotEchoChanged( int i )
{
switch ( i ) {
case 0:
<a name="x176"></a> lined1-><a href="tqlineedit.html#setEchoMode">setEchoMode</a>( TQLineEdit::Normal );
break;
case 1:
lined1-><a href="tqlineedit.html#setEchoMode">setEchoMode</a>( TQLineEdit::Password );
break;
case 2:
lined1-><a href="tqlineedit.html#setEchoMode">setEchoMode</a>( TQLineEdit::NoEcho );
break;
}
lined1-><a href="tqwidget.html#setFocus">setFocus</a>();
}
/*
* TQ_SLOT slotValidatorChanged( int i )
*
* i contains the number of the item which the user has been chosen in the
* second Combobox. According to this value, we set a validator for the
* second LineEdit. A validator checks in a LineEdit each character which
* the user enters and accepts it if it is valid, else the character gets
* ignored and not inserted into the lineedit.
*/
void <a name="f221"></a>LineEdits::slotValidatorChanged( int i )
{
switch ( i ) {
case 0:
<a name="x180"></a> lined2-><a href="tqlineedit.html#setValidator">setValidator</a>( 0 );
break;
case 1:
lined2-><a href="tqlineedit.html#setValidator">setValidator</a>( new <a href="tqintvalidator.html">TQIntValidator</a>( lined2 ) );
break;
case 2:
lined2-><a href="tqlineedit.html#setValidator">setValidator</a>( new <a href="tqdoublevalidator.html">TQDoubleValidator</a>( -999.0, 999.0, 2,
lined2 ) );
break;
}
<a name="x179"></a> lined2-><a href="tqlineedit.html#setText">setText</a>( "" );
lined2-><a href="tqwidget.html#setFocus">setFocus</a>();
}
/*
* TQ_SLOT slotAlignmentChanged( int i )
*
* i contains the number of the item which the user has been chosen in
* the third Combobox. According to this value, we set an alignment
* third LineEdit.
*/
void <a name="f222"></a>LineEdits::slotAlignmentChanged( int i )
{
switch ( i ) {
case 0:
<a name="x174"></a> lined3-><a href="tqlineedit.html#setAlignment">setAlignment</a>( TQLineEdit::AlignLeft );
break;
case 1:
lined3-><a href="tqlineedit.html#setAlignment">setAlignment</a>( TQLineEdit::AlignCenter );
break;
case 2:
lined3-><a href="tqlineedit.html#setAlignment">setAlignment</a>( TQLineEdit::AlignRight );
break;
}
lined3-><a href="tqwidget.html#setFocus">setFocus</a>();
}
/*
* TQ_SLOT slotInputMaskChanged( const <a href="tqstring.html">TQString</a> &mask )
*
* i contains the number of the item which the user has been chosen in
* the third Combobox. According to this value, we set an input mask on
* third LineEdit.
*/
void <a name="f223"></a>LineEdits::slotInputMaskChanged( int i )
{
switch( i ) {
case 0:
<a name="x177"></a> lined4-><a href="tqlineedit.html#setInputMask">setInputMask</a>( <a href="tqstring.html#TQString-null">TQString::null</a> );
break;
case 1:
lined4-><a href="tqlineedit.html#setInputMask">setInputMask</a>( "+99 99 99 99 99;_" );
break;
case 2:
lined4-><a href="tqlineedit.html#setInputMask">setInputMask</a>( "0000-00-00" );
lined4-><a href="tqlineedit.html#setText">setText</a>( "00000000" );
<a name="x175"></a> lined4-><a href="tqlineedit.html#setCursorPosition">setCursorPosition</a>( 0 );
break;
case 3:
lined4-><a href="tqlineedit.html#setInputMask">setInputMask</a>( ">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#" );
break;
}
lined4-><a href="tqwidget.html#setFocus">setFocus</a>();
}
/*
* TQ_SLOT slotReadOnlyChanged( int i )
*
* i contains the number of the item which the user has been chosen in
* the fourth Combobox. According to this value, we toggle read-only.
*/
void <a name="f224"></a>LineEdits::slotReadOnlyChanged( int i )
{
switch ( i ) {
case 0:
<a name="x178"></a> lined5-><a href="tqlineedit.html#setReadOnly">setReadOnly</a>( FALSE );
break;
case 1:
lined5-><a href="tqlineedit.html#setReadOnly">setReadOnly</a>( TRUE );
break;
}
lined5-><a href="tqwidget.html#setFocus">setFocus</a>();
}
</pre>
<p> <hr>
<p> Main:
<p> <pre>/****************************************************************************
** $Id: qt/main.cpp 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for TQt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include "lineedits.h"
#include <<a href="tqapplication-h.html">tqapplication.h</a>>
int main( int argc, char **argv )
{
<a href="tqapplication.html">TQApplication</a> a( argc, argv );
LineEdits lineedits;
lineedits.<a href="tqwidget.html#setCaption">setCaption</a>( "TQt Example - Lineedits" );
a.<a href="tqapplication.html#setMainWidget">setMainWidget</a>( &lineedits );
lineedits.<a href="tqwidget.html#show">show</a>();
return a.<a href="tqapplication.html#exec">exec</a>();
}
</pre>
<p>See also <a href="examples.html">Examples</a>.
<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright © 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>
|