com.trolltech.qt.gui
Class QLineEdit

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QWidget
                  extended by com.trolltech.qt.gui.QLineEdit
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QLineEdit
extends QWidget

The QLineEdit widget is a one-line text editor.

A line edit allows the user to enter and edit a single line of plain text with a useful collection of editing functions, including undo and redo, cut and paste, and drag and drop.

By changing the echoMode of a line edit, it can also be used as a "write-only" field, for inputs such as passwords.

The length of the text can be constrained to maxLength. The text can be arbitrarily constrained using a validator or an inputMask, or both.

A related class is QTextEdit which allows multi-line, rich text editing.

You can change the text with setText or insert. The text is retrieved with text; the displayed text (which may be different, see EchoMode) is retrieved with displayText. Text can be selected with setSelection or selectAll, and the selection can be cut, copyied and pasted. The text can be aligned with setAlignment.

When the text changes the textChanged signal is emitted; when the text changes other than by calling setText the textEdited signal is emitted; when the cursor is moved the cursorPositionChanged signal is emitted; and when the Return or Enter key is pressed the returnPressed signal is emitted.

When editing is finished, either because the line edit lost focus or Return/Enter is pressed the editingFinished signal is emitted.

Note that if there is a validator set on the line edit, the returnPressed/editingFinished signals will only be emitted if the validator returns QValidator::Acceptable.

By default, QLineEdits have a frame as specified by the Windows and Motif style guides; you can turn it off by calling setFrame(false).

The default key bindings are described below. The line edit also provides a context menu (usually invoked by a right mouse click) that presents some of these editing options.

KeypressAction
Left ArrowMoves the cursor one character to the left.
Shift+Left ArrowMoves and selects text one character to the left.
Right ArrowMoves the cursor one character to the right.
Shift+Right ArrowMoves and selects text one character to the right.
HomeMoves the cursor to the beginning of the line.
EndMoves the cursor to the end of the line.
BackspaceDeletes the character to the left of the cursor.
Ctrl+BackspaceDeletes the word to the left of the cursor.
DeleteDeletes the character to the right of the cursor.
Ctrl+DeleteDeletes the word to the right of the cursor.
Ctrl+ASelect all.
Ctrl+CCopies the selected text to the clipboard.
Ctrl+InsertCopies the selected text to the clipboard.
Ctrl+KDeletes to the end of the line.
Ctrl+VPastes the clipboard text into line edit.
Shift+InsertPastes the clipboard text into line edit.
Ctrl+XDeletes the selected text and copies it to the clipboard.
Shift+DeleteDeletes the selected text and copies it to the clipboard.
Ctrl+ZUndoes the last operation.
Ctrl+YRedoes the last undone operation.

Any other key sequence that represents a valid character, will cause the character to be inserted into the line edit.

Screenshot of a Macintosh style line editA line edit shown in the Macintosh widget style.
Screenshot of a Windows XP style line editA line edit shown in the Windows XP widget style.
Screenshot of a Plastique style line editA line edit shown in the Plastique widget style.

See Also:
QTextEdit, QLabel, QComboBox, GUI Design Handbook: Field, Entry, Line Edits Example

Nested Class Summary
static class QLineEdit.EchoMode
          This enum type describes how a line edit should display its contents.
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget
QWidget.RenderFlag, QWidget.RenderFlags
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 QSignalEmitter.Signal2<java.lang.Integer,java.lang.Integer> cursorPositionChanged
          This signal is emitted whenever the cursor moves.
 QSignalEmitter.Signal0 editingFinished
          This signal is emitted when the Return or Enter key is pressed or the line edit loses focus.
 QSignalEmitter.Signal0 returnPressed
          This signal is emitted when the Return or Enter key is pressed.
 QSignalEmitter.Signal0 selectionChanged
          This signal is emitted whenever the selection changes.
 QSignalEmitter.Signal1<java.lang.String> textChanged
          This signal is emitted whenever the text changes.
 QSignalEmitter.Signal1<java.lang.String> textEdited
          This signal is emitted whenever the text is edited.
 
Fields inherited from class com.trolltech.qt.gui.QWidget
customContextMenuRequested
 
Constructor Summary
QLineEdit()
          Equivalent to QLineEdit(0).
QLineEdit(QWidget parent)
          Constructs a line edit with no text.
QLineEdit(java.lang.String arg__1)
          Equivalent to QLineEdit(arg__1, 0).
QLineEdit(java.lang.String arg__1, QWidget parent)
          Constructs a line edit containing the text arg__1.
 
Method Summary
 Qt.Alignment alignment()
          Returns the alignment of the line edit.
 void backspace()
          If no text is selected, deletes the character to the left of the text cursor and moves the cursor one position to the left.
protected  void changeEvent(QEvent arg__1)
          This function is reimplemented for internal reasons.
 void clear()
          Clears the contents of the line edit.
 QCompleter completer()
          Returns the current QCompleter that provides completions.
protected  void contextMenuEvent(QContextMenuEvent arg__1)
          Shows the standard context menu created with createStandardContextMenu.
 void copy()
          Copies the selected text to the clipboard, if there is any, and if echoMode is Normal.
 QMenu createStandardContextMenu()
          This function creates the standard context menu which is shown when the user clicks on the line edit with the right mouse button.
 void cursorBackward(boolean mark)
          Equivalent to cursorBackward(mark, 1).
 void cursorBackward(boolean mark, int steps)
          Moves the cursor back steps characters.
 void cursorForward(boolean mark)
          Equivalent to cursorForward(mark, 1).
 void cursorForward(boolean mark, int steps)
          Moves the cursor forward steps characters.
 int cursorPosition()
          Returns the current cursor position for this line edit.
 int cursorPositionAt(QPoint pos)
          Returns the cursor position under the point pos.
 void cursorWordBackward(boolean mark)
          Moves the cursor one word backward.
 void cursorWordForward(boolean mark)
          Moves the cursor one word forward.
 void cut()
          Copies the selected text to the clipboard and deletes it, if there is any, and if echoMode is Normal.
 void del()
          If no text is selected, deletes the character to the right of the text cursor.
 void deselect()
          Deselects any selected text.
 java.lang.String displayText()
          Returns the displayed text.
 boolean dragEnabled()
          Returns whether the lineedit starts a drag if the user presses and moves the mouse on some selected text.
protected  void dragEnterEvent(QDragEnterEvent arg__1)
          This function is reimplemented for internal reasons.
protected  void dragLeaveEvent(QDragLeaveEvent e)
          This function is reimplemented for internal reasons.
protected  void dragMoveEvent(QDragMoveEvent e)
          This function is reimplemented for internal reasons.
protected  void dropEvent(QDropEvent arg__1)
          This function is reimplemented for internal reasons.
 QLineEdit.EchoMode echoMode()
          Returns the line edit's echo mode.
 void end(boolean mark)
          Moves the text cursor to the end of the line unless it is already there.
 boolean event(QEvent arg__1)
          This function is reimplemented for internal reasons.
protected  void focusInEvent(QFocusEvent arg__1)
          This function is reimplemented for internal reasons.
protected  void focusOutEvent(QFocusEvent arg__1)
          This function is reimplemented for internal reasons.
static QLineEdit fromNativePointer(QNativePointer nativePointer)
          This function returns the QLineEdit instance pointed to by nativePointer
 boolean hasAcceptableInput()
          Returns whether the input satisfies the inputMask and the validator..
 boolean hasFrame()
          Returns whether the line edit draws itself with a frame.
 boolean hasSelectedText()
          Returns whether there is any text selected.
 void home(boolean mark)
          Moves the text cursor to the beginning of the line unless it is already there.
protected  void initStyleOption(QStyleOptionFrame option)
          This is a overloaded function provided for convenience.
 java.lang.String inputMask()
          Returns The validation input mask.
protected  void inputMethodEvent(QInputMethodEvent arg__1)
          This function is reimplemented for internal reasons.
 java.lang.Object inputMethodQuery(Qt.InputMethodQuery arg__1)
          This function is reimplemented for internal reasons.
 void insert(java.lang.String arg__1)
          Deletes any selected text, inserts arg__1, and validates the result.
 boolean isModified()
          Returns whether the line edit's contents has been modified by the user.
 boolean isReadOnly()
          Returns whether the line edit is read only..
 boolean isRedoAvailable()
          Returns whether redo is available.
 boolean isUndoAvailable()
          Returns whether undo is available.
protected  void keyPressEvent(QKeyEvent arg__1)
          Converts the given key press arg__1 into a line edit action.
 int maxLength()
          Returns the maximum permitted length of the text.
 QSize minimumSizeHint()
          Returns a minimum size for the line edit.
protected  void mouseDoubleClickEvent(QMouseEvent arg__1)
          This function is reimplemented for internal reasons.
protected  void mouseMoveEvent(QMouseEvent arg__1)
          This function is reimplemented for internal reasons.
protected  void mousePressEvent(QMouseEvent arg__1)
          This function is reimplemented for internal reasons.
protected  void mouseReleaseEvent(QMouseEvent arg__1)
          This function is reimplemented for internal reasons.
protected  void paintEvent(QPaintEvent arg__1)
          This function is reimplemented for internal reasons.
 void paste()
          Inserts the clipboard's text at the cursor position, deleting any selected text, providing the line edit is not read-only.
 void redo()
          Redoes the last operation if redo is available.
 void selectAll()
          Selects all the text (i.e. highlights it) and moves the cursor to the end.
 java.lang.String selectedText()
          Returns the selected text.
 int selectionStart()
          selectionStart returns the index of the first selected character in the line edit or -1 if no text is selected.
 void setAlignment(Qt.Alignment flag)
          Sets the alignment of the line edit to flag.
 void setAlignment(Qt.AlignmentFlag... flag)
          Sets the alignment of the line edit to flag.
 void setCompleter(QCompleter completer)
          Sets this line edit to provide auto completions from the completer, completer.
 void setCursorPosition(int arg__1)
          Sets the current cursor position for this line edit to arg__1.
 void setDragEnabled(boolean b)
          Sets whether the lineedit starts a drag if the user presses and moves the mouse on some selected text to b.
 void setEchoMode(QLineEdit.EchoMode arg__1)
          Sets the line edit's echo mode to arg__1.
 void setFrame(boolean arg__1)
          Sets whether the line edit draws itself with a frame to arg__1.
 void setInputMask(java.lang.String inputMask)
          Sets The validation input mask to inputMask.
 void setMaxLength(int arg__1)
          Sets the maximum permitted length of the text to arg__1.
 void setModified(boolean arg__1)
          Sets whether the line edit's contents has been modified by the user to arg__1.
 void setReadOnly(boolean arg__1)
          Sets whether the line edit is read only.
 void setSelection(int arg__1, int arg__2)
          Selects text from position arg__1 and for arg__2 characters.
 void setText(java.lang.String arg__1)
          Sets the line edit's text to arg__1.
 void setValidator(QValidator arg__1)
          Sets this line edit to only accept input that the validator, arg__1, will accept.
 QSize sizeHint()
          Returns a recommended size for the widget.
 java.lang.String text()
          Returns the line edit's text.
 void undo()
          Undoes the last operation if undo is available.
 QValidator validator()
          Returns a pointer to the current input validator, or 0 if no validator has been set.
 
Methods inherited from class com.trolltech.qt.gui.QWidget
acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsRect, contextMenuPolicy, createWinId, cursor, depth, destroy, destroy, destroy, devType, ensurePolished, enterEvent, focusNextChild, focusNextPrevChild, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, hideEvent, inputContext, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, keyReleaseEvent, layout, layoutDirection, leaveEvent, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumWidth, mouseGrabber, move, move, moveEvent, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, overrideWindowState, paintEngine, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, resizeEvent, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setVisible, setWhatsThis, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showEvent, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, widthMM, window, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

cursorPositionChanged

public final QSignalEmitter.Signal2<java.lang.Integer,java.lang.Integer> cursorPositionChanged

This signal is emitted whenever the cursor moves. The previous position is given by arg__1, and the new position by arg__2.

Compatible Slot Signatures:
void mySlot(int arg__1, int arg__2)
void mySlot(int arg__1)
void mySlot()
See Also:
setCursorPosition, cursorPosition


editingFinished

public final QSignalEmitter.Signal0 editingFinished

This signal is emitted when the Return or Enter key is pressed or the line edit loses focus. Note that if there is a validator or inputMask set on the line edit and enter/return is pressed, the editingFinished signal will only be emitted if the input follows the inputMask and the validator returns QValidator::Acceptable.

Compatible Slot Signature:
void mySlot()


returnPressed

public final QSignalEmitter.Signal0 returnPressed

This signal is emitted when the Return or Enter key is pressed. Note that if there is a validator or inputMask set on the line edit, the returnPressed signal will only be emitted if the input follows the inputMask and the validator returns QValidator::Acceptable.

Compatible Slot Signature:
void mySlot()


selectionChanged

public final QSignalEmitter.Signal0 selectionChanged

This signal is emitted whenever the selection changes.

Compatible Slot Signature:
void mySlot()
See Also:
hasSelectedText, selectedText


textChanged

public final QSignalEmitter.Signal1<java.lang.String> textChanged

This signal is emitted whenever the text changes. The arg__1 argument is the new text.

Unlike textEdited, this signal is also emitted when the text is changed programmatically, for example, by calling setText.

Compatible Slot Signatures:
void mySlot(java.lang.String arg__1)
void mySlot()


textEdited

public final QSignalEmitter.Signal1<java.lang.String> textEdited

This signal is emitted whenever the text is edited. The arg__1 argument is the next text.

Unlike textChanged, this signal is not emitted when the text is changed programmatically, for example, by calling setText.

Compatible Slot Signatures:
void mySlot(java.lang.String arg__1)
void mySlot()

Constructor Detail

QLineEdit

public QLineEdit()

Equivalent to QLineEdit(0).


QLineEdit

public QLineEdit(QWidget parent)

Constructs a line edit with no text.

The maximum text length is set to 32767 characters.

The parent argument is sent to the QWidget constructor.

See Also:
setText, setMaxLength

QLineEdit

public QLineEdit(java.lang.String arg__1)

Equivalent to QLineEdit(arg__1, 0).


QLineEdit

public QLineEdit(java.lang.String arg__1,
                 QWidget parent)

Constructs a line edit containing the text arg__1.

The cursor position is set to the end of the line and the maximum text length to 32767 characters.

The parent and argument is sent to the QWidget constructor.

See Also:
text, setMaxLength
Method Detail

alignment

public final Qt.Alignment alignment()

Returns the alignment of the line edit.

Both horizontal and vertical alignment is allowed here, Qt::AlignJustify will map to Qt::AlignLeft.

See Also:
setAlignment, Qt::Alignment

backspace

public final void backspace()

If no text is selected, deletes the character to the left of the text cursor and moves the cursor one position to the left. If any text is selected, the cursor is moved to the beginning of the selected text and the selected text is deleted.

See Also:
del

clear

public final void clear()

Clears the contents of the line edit.

See Also:
setText, insert

completer

public final QCompleter completer()

Returns the current QCompleter that provides completions.

See Also:
setCompleter

copy

public final void copy()

Copies the selected text to the clipboard, if there is any, and if echoMode is Normal.

See Also:
cut, paste

createStandardContextMenu

public final QMenu createStandardContextMenu()

This function creates the standard context menu which is shown when the user clicks on the line edit with the right mouse button. It is called from the default contextMenuEvent handler. The popup menu's ownership is transferred to the caller.


cursorBackward

public final void cursorBackward(boolean mark)

Equivalent to cursorBackward(mark, 1).


cursorBackward

public final void cursorBackward(boolean mark,
                                 int steps)

Moves the cursor back steps characters. If mark is true each character moved over is added to the selection; if mark is false the selection is cleared.

See Also:
cursorForward

cursorForward

public final void cursorForward(boolean mark)

Equivalent to cursorForward(mark, 1).


cursorForward

public final void cursorForward(boolean mark,
                                int steps)

Moves the cursor forward steps characters. If mark is true each character moved over is added to the selection; if mark is false the selection is cleared.

See Also:
cursorBackward

cursorPosition

public final int cursorPosition()

Returns the current cursor position for this line edit.

Setting the cursor position causes a repaint when appropriate.

See Also:
setCursorPosition

cursorPositionAt

public final int cursorPositionAt(QPoint pos)

Returns the cursor position under the point pos.


cursorWordBackward

public final void cursorWordBackward(boolean mark)

Moves the cursor one word backward. If mark is true, the word is also selected.

See Also:
cursorWordForward

cursorWordForward

public final void cursorWordForward(boolean mark)

Moves the cursor one word forward. If mark is true, the word is also selected.

See Also:
cursorWordBackward

cut

public final void cut()

Copies the selected text to the clipboard and deletes it, if there is any, and if echoMode is Normal.

If the current validator disallows deleting the selected text, cut will copy without deleting.

See Also:
copy, paste, setValidator

del

public final void del()

If no text is selected, deletes the character to the right of the text cursor. If any text is selected, the cursor is moved to the beginning of the selected text and the selected text is deleted.

See Also:
backspace

deselect

public final void deselect()

Deselects any selected text.

See Also:
setSelection, selectAll

displayText

public final java.lang.String displayText()

Returns the displayed text.

If echoMode is Normal this returns the same as text; if EchoMode is Password or PasswordEchoOnEdit it returns a string of asterisks text.length characters long, e.g. "******"; if EchoMode is NoEcho returns an empty string, "".

See Also:
setEchoMode, text, EchoMode

dragEnabled

public final boolean dragEnabled()

Returns whether the lineedit starts a drag if the user presses and moves the mouse on some selected text.

Dragging is disabled by default.

See Also:
setDragEnabled

echoMode

public final QLineEdit.EchoMode echoMode()

Returns the line edit's echo mode.

The initial setting is Normal, but QLineEdit also supports NoEcho, Password and PasswordEchoOnEdit modes.

The widget's display and the ability to copy or drag the text is affected by this setting.

See Also:
setEchoMode, EchoMode, displayText

end

public final void end(boolean mark)

Moves the text cursor to the end of the line unless it is already there. If mark is true, text is selected towards the last position; otherwise, any selected text is unselected if the cursor is moved.

See Also:
home

hasAcceptableInput

public final boolean hasAcceptableInput()

Returns whether the input satisfies the inputMask and the validator..

See Also:
setInputMask, setValidator

hasFrame

public final boolean hasFrame()

Returns whether the line edit draws itself with a frame.

If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame.


hasSelectedText

public final boolean hasSelectedText()

Returns whether there is any text selected.

hasSelectedText returns true if some or all of the text has been selected by the user; otherwise returns false.

See Also:
selectedText

home

public final void home(boolean mark)

Moves the text cursor to the beginning of the line unless it is already there. If mark is true, text is selected towards the first position; otherwise, any selected text is unselected if the cursor is moved.

See Also:
end

inputMask

public final java.lang.String inputMask()

Returns The validation input mask.

If no mask is set, inputMask returns an empty string.

Sets the QLineEdit's validation mask. Validators can be used instead of, or in conjunction with masks; see setValidator.

Unset the mask and return to normal QLineEdit operation by passing an empty string ("") or just calling setInputMask with no arguments.

The mask format understands these mask characters:

CharacterMeaning
AASCII alphabetic character required. A-Z, a-z.
aASCII alphabetic character permitted but not required.
NASCII alphanumeric character required. A-Z, a-z, 0-9.
nASCII alphanumeric character permitted but not required.
XAny character required.
xAny character permitted but not required.
9ASCII digit required. 0-9.
0ASCII digit permitted but not required.
DASCII digit required. 1-9.
dASCII digit permitted but not required (1-9).
#ASCII digit or plus/minus sign permitted but not required.
HHexadecimal character required. A-F, a-f, 0-9.
hHexadecimal character permitted but not required.
BBinary character required. 0-1.
bBinary character permitted but not required.
>All following alphabetic characters are uppercased.
<All following alphabetic characters are lowercased.
!Switch off case conversion.
\Use \ to escape the special characters listed above to use them as separators.

The mask consists of a string of mask characters and separators, optionally followed by a semicolon and the character used for blanks: the blank characters are always removed from the text after editing. The default blank character is space.

Examples:

MaskNotes
000.000.000.000;_IP address; blanks are _.
HH:HH:HH:HH:HH:HH;_MAC address
0000-00-00ISO Date; blanks are space
>AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#License number; blanks are - and all (alphabetic) characters are converted to uppercase.

To get range control (e.g. for an IP address) use masks together with validators.

See Also:
setInputMask, maxLength

insert

public final void insert(java.lang.String arg__1)

Deletes any selected text, inserts arg__1, and validates the result. If it is valid, it sets it as the new contents of the line edit.

See Also:
setText, clear

isModified

public final boolean isModified()

Returns whether the line edit's contents has been modified by the user.

The modified flag is never read by QLineEdit; it has a default value of false and is changed to true whenever the user changes the line edit's contents.

This is useful for things that need to provide a default value but do not start out knowing what the default should be (perhaps it depends on other fields on the form). Start the line edit without the best default, and when the default is known, if modified() returns false (the user hasn't entered any text), insert the default value.

Calling setText resets the modified flag to false.


isReadOnly

public final boolean isReadOnly()

Returns whether the line edit is read only..

In read-only mode, the user can still copy the text to the clipboard, or drag and drop the text (if echoMode is Normal), but cannot edit it.

QLineEdit does not show a cursor in read-only mode.

See Also:
setEnabled

isRedoAvailable

public final boolean isRedoAvailable()

Returns whether redo is available.


isUndoAvailable

public final boolean isUndoAvailable()

Returns whether undo is available.


maxLength

public final int maxLength()

Returns the maximum permitted length of the text.

If the text is too long, it is truncated at the limit.

If truncation occurs any selected text will be unselected, the cursor position is set to 0 and the first part of the string is shown.

If the line edit has an input mask, the mask defines the maximum string length.

See Also:
setMaxLength, inputMask

paste

public final void paste()

Inserts the clipboard's text at the cursor position, deleting any selected text, providing the line edit is not read-only.

If the end result would not be acceptable to the current validator, nothing happens.

See Also:
copy, cut

redo

public final void redo()

Redoes the last operation if redo is available.


selectAll

public final void selectAll()

Selects all the text (i.e. highlights it) and moves the cursor to the end. This is useful when a default value has been inserted because if the user types before clicking on the widget, the selected text will be deleted.

See Also:
setSelection, deselect

selectedText

public final java.lang.String selectedText()

Returns the selected text.

If there is no selected text this property's value is an empty string.

See Also:
hasSelectedText

selectionStart

public final int selectionStart()

selectionStart returns the index of the first selected character in the line edit or -1 if no text is selected.

See Also:
selectedText

setAlignment

public final void setAlignment(Qt.AlignmentFlag... flag)

Sets the alignment of the line edit to flag.

Both horizontal and vertical alignment is allowed here, Qt::AlignJustify will map to Qt::AlignLeft.

See Also:
alignment, Qt::Alignment

setAlignment

public final void setAlignment(Qt.Alignment flag)

Sets the alignment of the line edit to flag.

Both horizontal and vertical alignment is allowed here, Qt::AlignJustify will map to Qt::AlignLeft.

See Also:
alignment, Qt::Alignment

setCompleter

public final void setCompleter(QCompleter completer)

Sets this line edit to provide auto completions from the completer, completer. The completion mode is set using QCompleter::setCompletionMode().

To use a QCompleter with a QValidator or QLineEdit::inputMask, you need to ensure that the model provided to QCompleter contains valid entries. You can use the QSortFilterProxyModel to ensure that the QCompleter's model contains only valid entries.

If completer == 0, setCompleter removes the current completer, effectively disabling auto completion.

See Also:
completer, QCompleter

setCursorPosition

public final void setCursorPosition(int arg__1)

Sets the current cursor position for this line edit to arg__1.

Setting the cursor position causes a repaint when appropriate.

See Also:
cursorPosition

setDragEnabled

public final void setDragEnabled(boolean b)

Sets whether the lineedit starts a drag if the user presses and moves the mouse on some selected text to b.

Dragging is disabled by default.

See Also:
dragEnabled

setEchoMode

public final void setEchoMode(QLineEdit.EchoMode arg__1)

Sets the line edit's echo mode to arg__1.

The initial setting is Normal, but QLineEdit also supports NoEcho, Password and PasswordEchoOnEdit modes.

The widget's display and the ability to copy or drag the text is affected by this setting.

See Also:
echoMode, EchoMode, displayText

setFrame

public final void setFrame(boolean arg__1)

Sets whether the line edit draws itself with a frame to arg__1.

If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame.

See Also:
hasFrame

setInputMask

public final void setInputMask(java.lang.String inputMask)

Sets The validation input mask to inputMask.

If no mask is set, inputMask returns an empty string.

Sets the QLineEdit's validation mask. Validators can be used instead of, or in conjunction with masks; see setValidator.

Unset the mask and return to normal QLineEdit operation by passing an empty string ("") or just calling setInputMask with no arguments.

The mask format understands these mask characters:

CharacterMeaning
AASCII alphabetic character required. A-Z, a-z.
aASCII alphabetic character permitted but not required.
NASCII alphanumeric character required. A-Z, a-z, 0-9.
nASCII alphanumeric character permitted but not required.
XAny character required.
xAny character permitted but not required.
9ASCII digit required. 0-9.
0ASCII digit permitted but not required.
DASCII digit required. 1-9.
dASCII digit permitted but not required (1-9).
#ASCII digit or plus/minus sign permitted but not required.
HHexadecimal character required. A-F, a-f, 0-9.
hHexadecimal character permitted but not required.
BBinary character required. 0-1.
bBinary character permitted but not required.
>All following alphabetic characters are uppercased.
<All following alphabetic characters are lowercased.
!Switch off case conversion.
\Use \ to escape the special characters listed above to use them as separators.

The mask consists of a string of mask characters and separators, optionally followed by a semicolon and the character used for blanks: the blank characters are always removed from the text after editing. The default blank character is space.

Examples:

MaskNotes
000.000.000.000;_IP address; blanks are _.
HH:HH:HH:HH:HH:HH;_MAC address
0000-00-00ISO Date; blanks are space
>AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#License number; blanks are - and all (alphabetic) characters are converted to uppercase.

To get range control (e.g. for an IP address) use masks together with validators.

See Also:
inputMask, maxLength

setMaxLength

public final void setMaxLength(int arg__1)

Sets the maximum permitted length of the text to arg__1.

If the text is too long, it is truncated at the limit.

If truncation occurs any selected text will be unselected, the cursor position is set to 0 and the first part of the string is shown.

If the line edit has an input mask, the mask defines the maximum string length.

See Also:
maxLength, inputMask

setModified

public final void setModified(boolean arg__1)

Sets whether the line edit's contents has been modified by the user to arg__1.

The modified flag is never read by QLineEdit; it has a default value of false and is changed to true whenever the user changes the line edit's contents.

This is useful for things that need to provide a default value but do not start out knowing what the default should be (perhaps it depends on other fields on the form). Start the line edit without the best default, and when the default is known, if modified() returns false (the user hasn't entered any text), insert the default value.

Calling setText resets the modified flag to false.

See Also:
isModified

setReadOnly

public final void setReadOnly(boolean arg__1)

Sets whether the line edit is read only. to arg__1.

In read-only mode, the user can still copy the text to the clipboard, or drag and drop the text (if echoMode is Normal), but cannot edit it.

QLineEdit does not show a cursor in read-only mode.

See Also:
isReadOnly, setEnabled

setSelection

public final void setSelection(int arg__1,
                               int arg__2)

Selects text from position arg__1 and for arg__2 characters. Negative lengths are allowed.

See Also:
deselect, selectAll, selectedText

setText

public final void setText(java.lang.String arg__1)

Sets the line edit's text to arg__1.

Setting this property clears the selection, clears the undo/redo history, moves the cursor to the end of the line and resets the modified property to false. The text is not validated when inserted with setText.

The text is truncated to maxLength length.

See Also:
text, insert, clear

setValidator

public final void setValidator(QValidator arg__1)

Sets this line edit to only accept input that the validator, arg__1, will accept. This allows you to place any arbitrary constraints on the text which may be entered.

If arg__1 == 0, setValidator removes the current input validator. The initial setting is to have no input validator (i.e. any input is accepted up to maxLength).

See Also:
validator, QIntValidator, QDoubleValidator, QRegExpValidator

text

public final java.lang.String text()

Returns the line edit's text.

Setting this property clears the selection, clears the undo/redo history, moves the cursor to the end of the line and resets the modified property to false. The text is not validated when inserted with setText.

The text is truncated to maxLength length.

See Also:
setText, insert, clear

undo

public final void undo()

Undoes the last operation if undo is available. Deselects any current selection, and updates the selection start to the current cursor position.


validator

public final QValidator validator()

Returns a pointer to the current input validator, or 0 if no validator has been set.

See Also:
setValidator

changeEvent

protected void changeEvent(QEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
changeEvent in class QWidget

contextMenuEvent

protected void contextMenuEvent(QContextMenuEvent arg__1)

Shows the standard context menu created with createStandardContextMenu.

If you do not want the line edit to have a context menu, you can set its contextMenuPolicy to Qt::NoContextMenu. If you want to customize the context menu, reimplement this function. If you want to extend the standard context menu, reimplement this function, call createStandardContextMenu and extend the menu returned.

    void LineEdit::contextMenuEvent(QContextMenuEvent *event)
    {
        QMenu *menu = createStandardContextMenu();
        menu->addAction(tr("My Menu Item"));
        //...
        menu->exec(event->globalPos());
        delete menu;
    }

The arg__1 parameter is used to obtain the position where the mouse cursor was when the event was generated.

Overrides:
contextMenuEvent in class QWidget
See Also:
setContextMenuPolicy

dragEnterEvent

protected void dragEnterEvent(QDragEnterEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
dragEnterEvent in class QWidget
See Also:
QTextDrag, QImageDrag, QDragEnterEvent

dragLeaveEvent

protected void dragLeaveEvent(QDragLeaveEvent e)

This function is reimplemented for internal reasons.

Overrides:
dragLeaveEvent in class QWidget
See Also:
QTextDrag, QImageDrag, QDragLeaveEvent

dragMoveEvent

protected void dragMoveEvent(QDragMoveEvent e)

This function is reimplemented for internal reasons.

Overrides:
dragMoveEvent in class QWidget
See Also:
QTextDrag, QImageDrag, QDragMoveEvent

dropEvent

protected void dropEvent(QDropEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
dropEvent in class QWidget
See Also:
QTextDrag, QImageDrag, QDropEvent

event

public boolean event(QEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
event in class QWidget
See Also:
closeEvent, focusInEvent, focusOutEvent, enterEvent, keyPressEvent, keyReleaseEvent, leaveEvent, mouseDoubleClickEvent, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, moveEvent, paintEvent, resizeEvent, QObject::event, QObject::timerEvent

focusInEvent

protected void focusInEvent(QFocusEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
focusInEvent in class QWidget
See Also:
focusOutEvent, setFocusPolicy, keyPressEvent, keyReleaseEvent, event, QFocusEvent

focusOutEvent

protected void focusOutEvent(QFocusEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
focusOutEvent in class QWidget
See Also:
focusInEvent, setFocusPolicy, keyPressEvent, keyReleaseEvent, event, QFocusEvent

inputMethodEvent

protected void inputMethodEvent(QInputMethodEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
inputMethodEvent in class QWidget
See Also:
event, QInputMethodEvent

inputMethodQuery

public java.lang.Object inputMethodQuery(Qt.InputMethodQuery arg__1)

This function is reimplemented for internal reasons.

Overrides:
inputMethodQuery in class QWidget
See Also:
inputMethodEvent, QInputMethodEvent, QInputContext

keyPressEvent

protected void keyPressEvent(QKeyEvent arg__1)

Converts the given key press arg__1 into a line edit action.

If Return or Enter is pressed and the current text is valid (or can be made valid by the validator), the signal returnPressed is emitted.

The default key bindings are listed in the class's detailed description.

Overrides:
keyPressEvent in class QWidget
See Also:
keyReleaseEvent, QKeyEvent::ignore, setFocusPolicy, focusInEvent, focusOutEvent, event, QKeyEvent, Tetrix Example

minimumSizeHint

public QSize minimumSizeHint()

Returns a minimum size for the line edit.

The width returned is enough for at least one character.

Overrides:
minimumSizeHint in class QWidget
See Also:
QSize::isValid, resize, setMinimumSize, sizePolicy

mouseDoubleClickEvent

protected void mouseDoubleClickEvent(QMouseEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
mouseDoubleClickEvent in class QWidget
See Also:
mousePressEvent, mouseReleaseEvent, mouseMoveEvent, event, QMouseEvent

mouseMoveEvent

protected void mouseMoveEvent(QMouseEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
mouseMoveEvent in class QWidget
See Also:
setMouseTracking, mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, event, QMouseEvent, Example

mousePressEvent

protected void mousePressEvent(QMouseEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
mousePressEvent in class QWidget
See Also:
mouseReleaseEvent, mouseDoubleClickEvent, mouseMoveEvent, event, QMouseEvent, Example

mouseReleaseEvent

protected void mouseReleaseEvent(QMouseEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
mouseReleaseEvent in class QWidget
See Also:
mousePressEvent, mouseDoubleClickEvent, mouseMoveEvent, event, QMouseEvent, Example

paintEvent

protected void paintEvent(QPaintEvent arg__1)

This function is reimplemented for internal reasons.

Overrides:
paintEvent in class QWidget
See Also:
event, repaint, update, QPainter, QPixmap, QPaintEvent, Analog Clock Example

sizeHint

public QSize sizeHint()

Returns a recommended size for the widget.

The width returned, in pixels, is usually enough for about 15 to 20 characters.

Overrides:
sizeHint in class QWidget
See Also:
QSize::isValid, minimumSizeHint, sizePolicy, setMinimumSize, updateGeometry

fromNativePointer

public static QLineEdit fromNativePointer(QNativePointer nativePointer)
This function returns the QLineEdit instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

initStyleOption

protected final void initStyleOption(QStyleOptionFrame option)
This is a overloaded function provided for convenience.