1QLineEdit(3qt) QLineEdit(3qt)
2
3
4
6 QLineEdit - One-line text editor
7
9 #include <qlineedit.h>
10
11 Inherits QFrame.
12
13 Public Members
14 QLineEdit ( QWidget * parent, const char * name = 0 )
15 QLineEdit ( const QString & contents, QWidget * parent, const char *
16 name = 0 )
17 QLineEdit ( const QString & contents, const QString & inputMask,
18 QWidget * parent, const char * name = 0 )
19 ~QLineEdit ()
20 QString text () const
21 QString displayText () const
22 int maxLength () const
23 bool frame () const
24 enum EchoMode { Normal, NoEcho, Password }
25 EchoMode echoMode () const
26 bool isReadOnly () const
27 const QValidator * validator () const
28 virtual QSize sizeHint () const
29 virtual QSize minimumSizeHint () const
30 int cursorPosition () const
31 bool validateAndSet ( const QString & newText, int newPos, int
32 newMarkAnchor, int newMarkDrag ) (obsolete)
33 int alignment () const
34 void cursorLeft ( bool mark, int steps = 1 ) (obsolete)
35 void cursorRight ( bool mark, int steps = 1 ) (obsolete)
36 void cursorForward ( bool mark, int steps = 1 )
37 void cursorBackward ( bool mark, int steps = 1 )
38 void cursorWordForward ( bool mark )
39 void cursorWordBackward ( bool mark )
40 void backspace ()
41 void del ()
42 void home ( bool mark )
43 void end ( bool mark )
44 bool isModified () const
45 void clearModified ()
46 bool edited () const (obsolete)
47 void setEdited ( bool ) (obsolete)
48 bool hasSelectedText () const
49 QString selectedText () const
50 int selectionStart () const
51 bool isUndoAvailable () const
52 bool isRedoAvailable () const
53 bool hasMarkedText () const (obsolete)
54 QString markedText () const (obsolete)
55 bool dragEnabled () const
56 QString inputMask () const
57 void setInputMask ( const QString & inputMask )
58 bool hasAcceptableInput () const
59 int characterAt ( int xpos, QChar * chr ) const (obsolete)
60 bool getSelection ( int * start, int * end ) (obsolete)
61
62 Public Slots
63 virtual void setText ( const QString & )
64 virtual void selectAll ()
65 virtual void deselect ()
66 virtual void clearValidator ()
67 virtual void insert ( const QString & newText )
68 virtual void clear ()
69 virtual void undo ()
70 virtual void redo ()
71 virtual void setMaxLength ( int )
72 virtual void setFrame ( bool )
73 virtual void setEchoMode ( EchoMode )
74 virtual void setReadOnly ( bool )
75 virtual void setValidator ( const QValidator * v )
76 virtual void setSelection ( int start, int length )
77 virtual void setCursorPosition ( int )
78 virtual void setAlignment ( int flag )
79 virtual void cut ()
80 virtual void copy () const
81 virtual void paste ()
82 virtual void setDragEnabled ( bool b )
83
84 Signals
85 void textChanged ( const QString & )
86 void returnPressed ()
87 void lostFocus ()
88 void selectionChanged ()
89
90 Properties
91 bool acceptableInput - whether the input satisfies the inputMask and
92 the validator (read only)
93 Alignment alignment - the alignment of the line edit
94 int cursorPosition - the current cursor position for this line edit
95 QString displayText - the displayed text (read only)
96 bool dragEnabled - whether the lineedit starts a drag if the user
97 presses and moves the mouse on some selected text
98 EchoMode echoMode - the line edit's echo mode
99 bool edited - whether the line edit has been edited. Use modified
100 instead (obsolete)
101 bool frame - whether the line edit draws itself with a frame
102 bool hasMarkedText - whether part of the text has been selected by the
103 user. Use hasSelectedText instead (read only) (obsolete)
104 bool hasSelectedText - whether there is any text selected (read only)
105 QString inputMask - the validation input mask
106 QString markedText - the text selected by the user. Use selectedText
107 instead (read only) (obsolete)
108 int maxLength - the maximum permitted length of the text
109 bool modified - whether the line edit's contents has been modified by
110 the user (read only)
111 bool readOnly - whether the line edit is read only
112 bool redoAvailable - whether redo is available (read only)
113 QString selectedText - the selected text (read only)
114 QString text - the line edit's text
115 bool undoAvailable - whether undo is available (read only)
116
117 Protected Members
118 virtual void keyPressEvent ( QKeyEvent * e )
119 virtual QPopupMenu * createPopupMenu ()
120 void repaintArea ( int from, int to ) (obsolete)
121
123 The QLineEdit widget is a one-line text editor.
124
125 A line edit allows the user to enter and edit a single line of plain
126 text with a useful collection of editing functions, including undo and
127 redo, cut and paste, and drag and drop.
128
129 By changing the echoMode() of a line edit, it can also be used as a
130 "write-only" field, for inputs such as passwords.
131
132 The length of the text can be constrained to maxLength(). The text can
133 be arbitrarily constrained using a validator() or an inputMask(), or
134 both.
135
136 A related class is QTextEdit which allows multi-line, rich-text
137 editing.
138
139 You can change the text with setText() or insert(). The text is
140 retrieved with text(); the displayed text (which may be different, see
141 EchoMode) is retrieved with displayText(). Text can be selected with
142 setSelection() or selectAll(), and the selection can be cut(),
143 copy()ied and paste()d. The text can be aligned with setAlignment().
144
145 When the text changes the textChanged() signal is emitted; when the
146 Return or Enter key is pressed the returnPressed() signal is emitted.
147 Note that if there is a validator set on the line edit, the
148 returnPressed() signal will only be emitted if the validator returns
149 Acceptable.
150
151 By default, QLineEdits have a frame as specified by the Windows and
152 Motif style guides; you can turn it off by calling setFrame(FALSE).
153
154 The default key bindings are described below. The line edit also
155 provides a context menu (usually invoked by a right mouse click) that
156 presents some of these editing options. <center>.nf
157
158 </center>
159
160 Any other key sequence that represents a valid character, will cause
161 the character to be inserted into the line edit.
162
163 [Image Omitted]
164
165 [Image Omitted]
166
167 See also QTextEdit, QLabel, QComboBox, GUI Design Handbook: Field,
168 Entry, and Basic Widgets.
169
170 Member Type Documentation
172 This enum type describes how a line edit should display its contents.
173
174 QLineEdit::Normal - Display characters as they are entered. This is the
175 default.
176
177 QLineEdit::NoEcho - Do not display anything. This may be appropriate
178 for passwords where even the length of the password should be kept
179 secret.
180
181 QLineEdit::Password - Display asterisks instead of the characters
182 actually entered.
183
184 See also echoMode and echoMode.
185
188 Constructs a line edit with no text.
189
190 The maximum text length is set to 32767 characters.
191
192 The parent and name arguments are sent to the QWidget constructor.
193
194 See also text and maxLength.
195
197 * name = 0 )
198 Constructs a line edit containing the text contents.
199
200 The cursor position is set to the end of the line and the maximum text
201 length to 32767 characters.
202
203 The parent and name arguments are sent to the QWidget constructor.
204
205 See also text and maxLength.
206
208 QWidget * parent, const char * name = 0 )
209 Constructs a line edit with an input inputMask and the text contents.
210
211 The cursor position is set to the end of the line and the maximum text
212 length is set to the length of the mask (the number of mask characters
213 and separators).
214
215 The parent and name arguments are sent to the QWidget constructor.
216
217 See also setMask() and text.
218
220 Destroys the line edit.
221
223 Returns the alignment of the line edit. See the "alignment" property
224 for details.
225
227 If no text is selected, deletes the character to the left of the text
228 cursor and moves the cursor one position to the left. If any text is
229 selected, the cursor is moved to the beginning of the selected text and
230 the selected text is deleted.
231
232 See also del().
233
235 This function is obsolete. It is provided to keep old source working.
236 We strongly advise against using it in new code.
237
239 Clears the contents of the line edit.
240
242 Resets the modified flag to FALSE.
243
244 See also modified.
245
247 This slot is equivalent to setValidator(0).
248
250 Copies the selected text to the clipboard, if there is any, and if
251 echoMode() is Normal.
252
253 See also cut() and paste().
254
256 This function is called to create the popup menu which is shown when
257 the user clicks on the line edit with the right mouse button. If you
258 want to create a custom popup menu, reimplement this function and
259 return the popup menu you create. The popup menu's ownership is
260 transferred to the caller.
261
263 Moves the cursor back steps characters. If mark is TRUE each character
264 moved over is added to the selection; if mark is FALSE the selection is
265 cleared.
266
267 See also cursorForward().
268
270 Moves the cursor forward steps characters. If mark is TRUE each
271 character moved over is added to the selection; if mark is FALSE the
272 selection is cleared.
273
274 See also cursorBackward().
275
277 This function is obsolete. It is provided to keep old source working.
278 We strongly advise against using it in new code.
279
280 For compatibilty with older applications only. Use cursorBackward()
281 instead.
282
283 See also cursorBackward().
284
286 Returns the current cursor position for this line edit. See the
287 "cursorPosition" property for details.
288
290 This function is obsolete. It is provided to keep old source working.
291 We strongly advise against using it in new code.
292
293 Use cursorForward() instead.
294
295 See also cursorForward().
296
298 Moves the cursor one word backward. If mark is TRUE, the word is also
299 selected.
300
301 See also cursorWordForward().
302
304 Moves the cursor one word forward. If mark is TRUE, the word is also
305 selected.
306
307 See also cursorWordBackward().
308
310 Copies the selected text to the clipboard and deletes it, if there is
311 any, and if echoMode() is Normal.
312
313 If the current validator disallows deleting the selected text, cut()
314 will copy without deleting.
315
316 See also copy(), paste(), and setValidator().
317
319 If no text is selected, deletes the character to the right of the text
320 cursor. If any text is selected, the cursor is moved to the beginning
321 of the selected text and the selected text is deleted.
322
323 See also backspace().
324
326 Deselects any selected text.
327
328 See also setSelection() and selectAll().
329
331 Returns the displayed text. See the "displayText" property for details.
332
334 Returns TRUE if the lineedit starts a drag if the user presses and
335 moves the mouse on some selected text; otherwise returns FALSE. See the
336 "dragEnabled" property for details.
337
339 Returns the line edit's echo mode. See the "echoMode" property for
340 details.
341
343 Returns TRUE if the line edit has been edited. Use modified instead;
344 otherwise returns FALSE. See the "edited" property for details.
345
347 Moves the text cursor to the end of the line unless it is already
348 there. If mark is TRUE, text is selected towards the last position;
349 otherwise, any selected text is unselected if the cursor is moved.
350
351 See also home().
352
354 Returns TRUE if the line edit draws itself with a frame; otherwise
355 returns FALSE. See the "frame" property for details.
356
358 This function is obsolete. It is provided to keep old source working.
359 We strongly advise against using it in new code. use selectedText(),
360 selectionStart()
361
363 Returns TRUE if the input satisfies the inputMask and the validator;
364 otherwise returns FALSE. See the "acceptableInput" property for
365 details.
366
368 Returns TRUE if part of the text has been selected by the user. Use
369 hasSelectedText instead; otherwise returns FALSE. See the
370 "hasMarkedText" property for details.
371
373 Returns TRUE if there is any text selected; otherwise returns FALSE.
374 See the "hasSelectedText" property for details.
375
377 Moves the text cursor to the beginning of the line unless it is already
378 there. If mark is TRUE, text is selected towards the first position;
379 otherwise, any selected text is unselected if the cursor is moved.
380
381 See also end().
382
384 Returns the validation input mask. See the "inputMask" property for
385 details.
386
388 Deletes any selected text, inserts newText, and validates the result.
389 If it is valid, it sets it as the new contents of the line edit.
390
392 Returns TRUE if the line edit's contents has been modified by the user;
393 otherwise returns FALSE. See the "modified" property for details.
394
396 Returns TRUE if the line edit is read only; otherwise returns FALSE.
397 See the "readOnly" property for details.
398
400 Returns TRUE if redo is available; otherwise returns FALSE. See the
401 "redoAvailable" property for details.
402
404 Returns TRUE if undo is available; otherwise returns FALSE. See the
405 "undoAvailable" property for details.
406
408 Converts key press event e into a line edit action.
409
410 If Return or Enter is pressed and the current text is valid (or can be
411 made valid by the validator), the signal returnPressed() is emitted.
412
413 The default key bindings are listed in the detailed description.
414
415 Reimplemented from QWidget.
416
418 This signal is emitted when the line edit has lost focus.
419
420 See also focus, QWidget::focusInEvent(), and QWidget::focusOutEvent().
421
423 Returns the text selected by the user. Use selectedText instead. See
424 the "markedText" property for details.
425
427 Returns the maximum permitted length of the text. See the "maxLength"
428 property for details.
429
431 Returns a minimum size for the line edit.
432
433 The width returned is enough for at least one character.
434
435 Reimplemented from QWidget.
436
438 Inserts the clipboard's text at the cursor position, deleting any
439 selected text, providing the line edit is not read-only.
440
441 If the end result would not be acceptable to the current validator,
442 nothing happens.
443
444 See also copy() and cut().
445
447 Redoes the last operation if redo is available.
448
450 This function is obsolete. It is provided to keep old source working.
451 We strongly advise against using it in new code.
452
453 Repaints all characters from from to to. If cursorPos is between from
454 and to, ensures that cursorPos is visible.
455
457 This signal is emitted when the Return or Enter key is pressed. Note
458 that if there is a validator() or inputMask() set on the line edit, the
459 returnPressed() signal will only be emitted if the input follows the
460 inputMask() and the validator() returns Acceptable.
461
462 Example: popup/popup.cpp.
463
465 Selects all the text (i.e. highlights it) and moves the cursor to the
466 end. This is useful when a default value has been inserted because if
467 the user types before clicking on the widget, the selected text will be
468 deleted.
469
470 See also setSelection() and deselect().
471
473 Returns the selected text. See the "selectedText" property for details.
474
476 This signal is emitted whenever the selection changes.
477
478 See also hasSelectedText and selectedText.
479
481 selectionStart() returns the index of the first selected character in
482 the line edit or -1 if no text is selected.
483
484 See also selectedText.
485
487 Sets the alignment of the line edit to flag. See the "alignment"
488 property for details.
489
491 Sets the current cursor position for this line edit. See the
492 "cursorPosition" property for details.
493
495 Sets whether the lineedit starts a drag if the user presses and moves
496 the mouse on some selected text to b. See the "dragEnabled" property
497 for details.
498
500 Sets the line edit's echo mode. See the "echoMode" property for
501 details.
502
504 Sets whether the line edit has been edited. Use modified instead. See
505 the "edited" property for details.
506
508 Sets whether the line edit draws itself with a frame. See the "frame"
509 property for details.
510
512 Sets the validation input mask to inputMask. See the "inputMask"
513 property for details.
514
516 Sets the maximum permitted length of the text. See the "maxLength"
517 property for details.
518
520 Sets whether the line edit is read only. See the "readOnly" property
521 for details.
522
524 Selects text from position start and for length characters.
525
526 Note that this function sets the cursor's position to the end of the
527 selection regardless of its current position.
528
529 See also deselect(), selectAll(), getSelection(), cursorForward(), and
530 cursorBackward().
531
533 Sets the line edit's text. See the "text" property for details.
534
536 Sets this line edit to only accept input that the validator, v, will
537 accept. This allows you to place any arbitrary constraints on the text
538 which may be entered.
539
540 If v == 0, setValidator() removes the current input validator. The
541 initial setting is to have no input validator (i.e. any input is
542 accepted up to maxLength()).
543
544 See also validator(), QIntValidator, QDoubleValidator, and
545 QRegExpValidator.
546
547 Examples:
548
550 Returns a recommended size for the widget.
551
552 The width returned, in pixels, is usually enough for about 15 to 20
553 characters.
554
555 Example: addressbook/centralwidget.cpp.
556
558 Returns the line edit's text. See the "text" property for details.
559
561 This signal is emitted whenever the text changes. The argument is the
562 new text.
563
564 Examples:
565
567 Undoes the last operation if undo is available. Deselects any current
568 selection, and updates the selection start to the current cursor
569 position.
570
572 newMarkAnchor, int newMarkDrag )
573 This function is obsolete. It is provided to keep old source working.
574 We strongly advise against using it in new code. Use setText(),
575 setCursorPosition() and setSelection() instead.
576
578 Returns a pointer to the current input validator, or 0 if no validator
579 has been set.
580
581 See also setValidator().
582
583 Example: wizard/wizard.cpp.
584
585 Property Documentation
587 This property holds whether the input satisfies the inputMask and the
588 validator.
589
590 Get this property's value with hasAcceptableInput().
591
592 See also inputMask and setValidator().
593
595 This property holds the alignment of the line edit.
596
597 Possible Values are Qt::AlignAuto, Qt::AlignLeft, Qt::AlignRight and
598 Qt::AlignHCenter.
599
600 Attempting to set the alignment to an illegal flag combination does
601 nothing.
602
603 See also Qt::AlignmentFlags.
604
605 Set this property's value with setAlignment() and get this property's
606 value with alignment().
607
609 This property holds the current cursor position for this line edit.
610
611 Setting the cursor position causes a repaint when appropriate.
612
613 Set this property's value with setCursorPosition() and get this
614 property's value with cursorPosition().
615
617 This property holds the displayed text.
618
619 If EchoMode is Normal this returns the same as text(); if EchoMode is
620 Password it returns a string of asterisks text().length() characters
621 long, e.g. "******"; if EchoMode is NoEcho returns an empty string, "".
622
623 See also echoMode, text, and EchoMode.
624
625 Get this property's value with displayText().
626
628 This property holds whether the lineedit starts a drag if the user
629 presses and moves the mouse on some selected text.
630
631 Set this property's value with setDragEnabled() and get this property's
632 value with dragEnabled().
633
635 This property holds the line edit's echo mode.
636
637 The initial setting is Normal, but QLineEdit also supports NoEcho and
638 Password modes.
639
640 The widget's display and the ability to copy or drag the text is
641 affected by this setting.
642
643 See also EchoMode and displayText.
644
645 Set this property's value with setEchoMode() and get this property's
646 value with echoMode().
647
649 This function is obsolete. It is provided to keep old source working.
650 We strongly advise against using it in new code.
651
652 This property holds whether the line edit has been edited. Use modified
653 instead.
654
655 Set this property's value with setEdited() and get this property's
656 value with edited().
657
659 This property holds whether the line edit draws itself with a frame.
660
661 If enabled (the default) the line edit draws itself inside a two-pixel
662 frame, otherwise the line edit draws itself without any frame.
663
664 Set this property's value with setFrame() and get this property's value
665 with frame().
666
668 This function is obsolete. It is provided to keep old source working.
669 We strongly advise against using it in new code.
670
671 This property holds whether part of the text has been selected by the
672 user. Use hasSelectedText instead.
673
674 Get this property's value with hasMarkedText().
675
677 This property holds whether there is any text selected.
678
679 hasSelectedText() returns TRUE if some or all of the text has been
680 selected by the user; otherwise returns FALSE.
681
682 See also selectedText.
683
684 Get this property's value with hasSelectedText().
685
687 This property holds the validation input mask.
688
689 If no mask is set, inputMask() returns QString::null.
690
691 Sets the QLineEdit's validation mask. Validators can be used instead
692 of, or in conjunction with masks; see setValidator().
693
694 Unset the mask and return to normal QLineEdit operation by passing an
695 empty string ("") or just calling setInputMask() with no arguments.
696
697 The mask format understands these mask characters: <center>.nf
698
699 </center>
700
701 The mask consists of a string of mask characters and separators,
702 optionally followed by a semi-colon and the character used for blanks:
703 the blank characters are always removed from the text after editing.
704 The default blank character is space.
705
706 Examples: <center>.nf
707
708 </center>
709
710 To get range control (e.g. for an IP address) use masks together with
711 validators.
712
713 See also maxLength.
714
715 Set this property's value with setInputMask() and get this property's
716 value with inputMask().
717
719 This function is obsolete. It is provided to keep old source working.
720 We strongly advise against using it in new code.
721
722 This property holds the text selected by the user. Use selectedText
723 instead.
724
725 Get this property's value with markedText().
726
728 This property holds the maximum permitted length of the text.
729
730 If the text is too long, it is truncated at the limit.
731
732 If truncation occurs any selected text will be unselected, the cursor
733 position is set to 0 and the first part of the string is shown.
734
735 If the line edit has an input mask, the mask defines the maximum string
736 length.
737
738 See also inputMask.
739
740 Set this property's value with setMaxLength() and get this property's
741 value with maxLength().
742
744 This property holds whether the line edit's contents has been modified
745 by the user.
746
747 The modified flag is never read by QLineEdit; it has a default value of
748 FALSE and is changed to TRUE whenever the user changes the line edit's
749 contents.
750
751 This is useful for things that need to provide a default value but do
752 not start out knowing what the default should be (perhaps it depends on
753 other fields on the form). Start the line edit without the best
754 default, and when the default is known, if modified() returns FALSE
755 (the user hasn't entered any text), insert the default value.
756
757 Calling clearModified() or setText() resets the modified flag to FALSE.
758
759 Get this property's value with isModified().
760
762 This property holds whether the line edit is read only.
763
764 In read-only mode, the user can still copy the text to the clipboard or
765 drag-and-drop the text (if echoMode() is Normal), but cannot edit it.
766
767 QLineEdit does not show a cursor in read-only mode.
768
769 See also enabled.
770
771 Set this property's value with setReadOnly() and get this property's
772 value with isReadOnly().
773
775 This property holds whether redo is available.
776
777 Get this property's value with isRedoAvailable().
778
780 This property holds the selected text.
781
782 If there is no selected text this property's value is QString::null.
783
784 See also hasSelectedText.
785
786 Get this property's value with selectedText().
787
789 This property holds the line edit's text.
790
791 Note that setting this property clears the selection, clears the
792 undo/redo history, moves the cursor to the end of the line and resets
793 the modified property to FALSE. The text is not validated when inserted
794 with setText().
795
796 The text is truncated to maxLength() length.
797
798 See also insert().
799
800 Set this property's value with setText() and get this property's value
801 with text().
802
804 This property holds whether undo is available.
805
806 Get this property's value with isUndoAvailable().
807
808
810 http://doc.trolltech.com/qlineedit.html
811 http://www.trolltech.com/faq/tech.html
812
814 Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
815 license file included in the distribution for a complete license
816 statement.
817
819 Generated automatically from the source code.
820
822 If you find a bug in Qt, please report it as described in
823 http://doc.trolltech.com/bughowto.html. Good bug reports help us to
824 help you. Thank you.
825
826 The definitive Qt documentation is provided in HTML format; it is
827 located at $QTDIR/doc/html and can be read using Qt Assistant or with a
828 web browser. This man page is provided as a convenience for those users
829 who prefer man pages, although this format is not officially supported
830 by Trolltech.
831
832 If you find errors in this manual page, please report them to qt-
833 bugs@trolltech.com. Please include the name of the manual page
834 (qlineedit.3qt) and the Qt version (3.3.8).
835
836
837
838Trolltech AS 2 February 2007 QLineEdit(3qt)