Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QLineEdit Class

TheQLineEdit widget is a one-line text editor.More...

Header:#include <QLineEdit>
Inherits:QWidget

Public Types

enumEchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit }

Properties

Public Functions

QLineEdit(QWidget * parent = 0)
QLineEdit(const QString & contents, QWidget * parent = 0)
~QLineEdit()
Qt::Alignmentalignment() const
voidbackspace()
QCompleter *completer() const
QMenu *createStandardContextMenu()
voidcursorBackward(bool mark, int steps = 1)
voidcursorForward(bool mark, int steps = 1)
Qt::CursorMoveStylecursorMoveStyle() const
intcursorPosition() const
intcursorPositionAt(const QPoint & pos)
voidcursorWordBackward(bool mark)
voidcursorWordForward(bool mark)
voiddel()
voiddeselect()
QStringdisplayText() const
booldragEnabled() const
EchoModeechoMode() const
voidend(bool mark)
voidgetTextMargins(int * left, int * top, int * right, int * bottom) const
boolhasAcceptableInput() const
boolhasFrame() const
boolhasSelectedText() const
voidhome(bool mark)
QStringinputMask() const
voidinsert(const QString & newText)
boolisModified() const
boolisReadOnly() const
boolisRedoAvailable() const
boolisUndoAvailable() const
intmaxLength() const
QStringplaceholderText() const
QStringselectedText() const
intselectionStart() const
voidsetAlignment(Qt::Alignment flag)
voidsetCompleter(QCompleter * c)
voidsetCursorMoveStyle(Qt::CursorMoveStyle style)
voidsetCursorPosition(int)
voidsetDragEnabled(bool b)
voidsetEchoMode(EchoMode)
voidsetFrame(bool)
voidsetInputMask(const QString & inputMask)
voidsetMaxLength(int)
voidsetModified(bool)
voidsetPlaceholderText(const QString &)
voidsetReadOnly(bool)
voidsetSelection(int start, int length)
voidsetTextMargins(int left, int top, int right, int bottom)
voidsetTextMargins(const QMargins & margins)
voidsetValidator(const QValidator * v)
QStringtext() const
QMarginstextMargins() const
const QValidator *validator() const

Reimplemented Public Functions

virtual boolevent(QEvent * e)
virtual QVariantinputMethodQuery(Qt::InputMethodQuery property) const
virtual QSizeminimumSizeHint() const
virtual QSizesizeHint() const

Public Slots

voidclear()
voidcopy() const
voidcut()
voidpaste()
voidredo()
voidselectAll()
voidsetText(const QString &)
voidundo()
  • 19 public slots inherited fromQWidget
  • 1 public slot inherited fromQObject

Signals

voidcursorPositionChanged(int old, int new)
voideditingFinished()
voidreturnPressed()
voidselectionChanged()
voidtextChanged(const QString & text)
voidtextEdited(const QString & text)

Protected Functions

QRectcursorRect() const
voidinitStyleOption(QStyleOptionFrame * option) const

Reimplemented Protected Functions

virtual voidchangeEvent(QEvent * ev)
virtual voidcontextMenuEvent(QContextMenuEvent * event)
virtual voiddragEnterEvent(QDragEnterEvent * e)
virtual voiddragLeaveEvent(QDragLeaveEvent * e)
virtual voiddragMoveEvent(QDragMoveEvent * e)
virtual voiddropEvent(QDropEvent * e)
virtual voidfocusInEvent(QFocusEvent * e)
virtual voidfocusOutEvent(QFocusEvent * e)
virtual voidinputMethodEvent(QInputMethodEvent * e)
virtual voidkeyPressEvent(QKeyEvent * event)
virtual voidmouseDoubleClickEvent(QMouseEvent * e)
virtual voidmouseMoveEvent(QMouseEvent * e)
virtual voidmousePressEvent(QMouseEvent * e)
virtual voidmouseReleaseEvent(QMouseEvent * e)
virtual voidpaintEvent(QPaintEvent *)
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice

Additional Inherited Members

  • 4 static public members inherited fromQWidget
  • 7 static public members inherited fromQObject
  • 1 protected slot inherited fromQWidget

Detailed Description

TheQLineEdit 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 theechoMode() 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 tomaxLength(). The text can be arbitrarily constrained using avalidator() or aninputMask(), or both. When switching between a validator and an input mask on the same line edit, it is best to clear the validator or input mask to prevent undefined behavior.

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

You can change the text withsetText() orinsert(). The text is retrieved withtext(); the displayed text (which may be different, seeEchoMode) is retrieved withdisplayText(). Text can be selected withsetSelection() orselectAll(), and the selection can becut(),copy()ied andpaste()d. The text can be aligned withsetAlignment().

When the text changes thetextChanged() signal is emitted; when the text changes other than by callingsetText() thetextEdited() signal is emitted; when the cursor is moved thecursorPositionChanged() signal is emitted; and when the Return or Enter key is pressed thereturnPressed() signal is emitted.

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

Note that if there is a validator set on the line edit, thereturnPressed()/editingFinished() signals will only be emitted if the validator returnsQValidator::Acceptable.

By default, QLineEdits have a frame as specified by the Windows and Motif style guides; you can turn it off by callingsetFrame(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 theMacintosh widget style.
Screenshot of a Windows XP style line editA line edit shown in theWindows XP widget style.
Screenshot of a Plastique style line editA line edit shown in thePlastique widget style.

See alsoQTextEdit,QLabel,QComboBox,GUI Design Handbook: Field, Entry, andLine Edits Example.

Member Type Documentation

enum QLineEdit::EchoMode

This enum type describes how a line edit should display its contents.

ConstantValueDescription
QLineEdit::Normal0Display characters as they are entered. This is the default.
QLineEdit::NoEcho1Do not display anything. This may be appropriate for passwords where even the length of the password should be kept secret.
QLineEdit::Password2Display asterisks instead of the characters actually entered.
QLineEdit::PasswordEchoOnEdit3Display characters as they are entered while editing otherwise display asterisks.

See alsosetEchoMode() andechoMode().

Property Documentation

acceptableInput : constbool

This property holds whether the input satisfies the inputMask and the validator.

By default, this property is true.

Access functions:

boolhasAcceptableInput() const

See alsosetInputMask() andsetValidator().

alignment :Qt::Alignment

This property holds the alignment of the line edit.

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

By default, this property contains a combination ofQt::AlignLeft andQt::AlignVCenter.

Access functions:

Qt::Alignmentalignment() const
voidsetAlignment(Qt::Alignment flag)

See alsoQt::Alignment.

cursorMoveStyle :Qt::CursorMoveStyle

This property holds the movement style of cursor in this line edit.

When this property is set toQt::VisualMoveStyle, the line edit will use visual movement style. Pressing the left arrow key will always cause the cursor to move left, regardless of the text's writing direction. The same behavior applies to right arrow key.

When the property isQt::LogicalMoveStyle (the default), within a LTR text block, increase cursor position when pressing left arrow key, decrease cursor position when pressing the right arrow key. If the text block is right to left, the opposite behavior applies.

This property was introduced in Qt 4.8.

Access functions:

Qt::CursorMoveStylecursorMoveStyle() const
voidsetCursorMoveStyle(Qt::CursorMoveStyle style)

cursorPosition :int

This property holds the current cursor position for this line edit.

Setting the cursor position causes a repaint when appropriate.

By default, this property contains a value of 0.

Access functions:

intcursorPosition() const
voidsetCursorPosition(int)

displayText : constQString

This property holds the displayed text.

IfechoMode isNormal this returns the same astext(); ifEchoMode isPassword orPasswordEchoOnEdit it returns a string of asteriskstext().length() characters long, e.g. "******"; ifEchoMode isNoEcho returns an empty string, "".

By default, this property contains an empty string.

Access functions:

QStringdisplayText() const

See alsosetEchoMode(),text(), andEchoMode.

dragEnabled :bool

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

Dragging is disabled by default.

Access functions:

booldragEnabled() const
voidsetDragEnabled(bool b)

echoMode :EchoMode

This property holds the line edit's echo mode.

The echo mode determines how the text entered in the line edit is displayed (or echoed) to the user.

The most common setting isNormal, in which the text entered by the user is displayed verbatim, butQLineEdit also supports modes that allow the entered text to be suppressed or obscured: these includeNoEcho,Password andPasswordEchoOnEdit.

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

By default, this property is set toNormal.

Access functions:

EchoModeechoMode() const
voidsetEchoMode(EchoMode)

See alsoEchoMode anddisplayText().

frame :bool

This property holds 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.

Access functions:

boolhasFrame() const
voidsetFrame(bool)

hasSelectedText : constbool

This property holds 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.

By default, this property is false.

Access functions:

boolhasSelectedText() const

See alsoselectedText().

inputMask :QString

This property holds the validation input mask.

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

Sets theQLineEdit's validation mask. Validators can be used instead of, or in conjunction with masks; seesetValidator().

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

The table below shows the characters that can be used in an input mask. A space character, the default character for a blank, is needed for cases where a character ispermitted but not required.

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.

Examples:

MaskNotes
000.000.000.000;_IP address; blanks are_.
HH:HH:HH:HH:HH:HH;_MAC address
0000-00-00ISO Date; blanks arespace
>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 withvalidators.

Access functions:

QStringinputMask() const
voidsetInputMask(const QString & inputMask)

See alsomaxLength.

maxLength :int

This property holds 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.

By default, this property contains a value of 32767.

Access functions:

intmaxLength() const
voidsetMaxLength(int)

See alsoinputMask.

modified :bool

This property holds whether the line edit's contents has been modified by the user.

The modified flag is never read byQLineEdit; 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.

CallingsetText() resets the modified flag to false.

Access functions:

boolisModified() const
voidsetModified(bool)

placeholderText :QString

This property holds the line edit's placeholder text.

Setting this property makes the line edit display a grayed-out placeholder text as long as thetext() is empty and the widget doesn't have focus.

By default, this property contains an empty string.

This property was introduced in Qt 4.7.

Access functions:

QStringplaceholderText() const
voidsetPlaceholderText(const QString &)

See alsotext().

readOnly :bool

This property holds 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 (ifechoMode() isNormal), but cannot edit it.

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

By default, this property is false.

Access functions:

boolisReadOnly() const
voidsetReadOnly(bool)

See alsosetEnabled().

redoAvailable : constbool

This property holds whether redo is available.

Redo becomes available once the user has performed one or more undo operations on text in the line edit.

By default, this property is false.

Access functions:

boolisRedoAvailable() const

selectedText : constQString

This property holds the selected text.

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

By default, this property contains an empty string.

Access functions:

QStringselectedText() const

See alsohasSelectedText().

text :QString

This property holds 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 themodified property to false. The text is not validated when inserted with setText().

The text is truncated tomaxLength() length.

By default, this property contains an empty string.

Access functions:

QStringtext() const
voidsetText(const QString &)

Notifier signal:

voidtextChanged(const QString & text)

See alsoinsert() andclear().

undoAvailable : constbool

This property holds whether undo is available.

Undo becomes available once the user has modified the text in the line edit.

By default, this property is false.

Access functions:

boolisUndoAvailable() const

Member Function Documentation

QLineEdit::QLineEdit(QWidget * parent = 0)

Constructs a line edit with no text.

The maximum text length is set to 32767 characters.

Theparent argument is sent to theQWidget constructor.

See alsosetText() andsetMaxLength().

QLineEdit::QLineEdit(constQString & contents,QWidget * parent = 0)

Constructs a line edit containing the textcontents.

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

Theparent and argument is sent to theQWidget constructor.

See alsotext() andsetMaxLength().

QLineEdit::~QLineEdit()

Destroys the line edit.

void QLineEdit::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 alsodel().

[virtual protected]void QLineEdit::changeEvent(QEvent * ev)

Reimplemented fromQWidget::changeEvent().

[slot]void QLineEdit::clear()

Clears the contents of the line edit.

See alsosetText() andinsert().

QCompleter * QLineEdit::completer() const

Returns the currentQCompleter that provides completions.

This function was introduced in Qt 4.2.

See alsosetCompleter().

[virtual protected]void QLineEdit::contextMenuEvent(QContextMenuEvent * event)

Reimplemented fromQWidget::contextMenuEvent().

Shows the standard context menu created withcreateStandardContextMenu().

If you do not want the line edit to have a context menu, you can set itscontextMenuPolicy toQt::NoContextMenu. If you want to customize the context menu, reimplement this function. If you want to extend the standard context menu, reimplement this function, callcreateStandardContextMenu() 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;}

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

See alsosetContextMenuPolicy().

[slot]void QLineEdit::copy() const

Copies the selected text to the clipboard, if there is any, and ifechoMode() isNormal.

See alsocut() andpaste().

QMenu * QLineEdit::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 defaultcontextMenuEvent() handler. The popup menu's ownership is transferred to the caller.

void QLineEdit::cursorBackward(bool mark,int steps = 1)

Moves the cursor backsteps characters. Ifmark is true each character moved over is added to the selection; ifmark is false the selection is cleared.

See alsocursorForward().

void QLineEdit::cursorForward(bool mark,int steps = 1)

Moves the cursor forwardsteps characters. Ifmark is true each character moved over is added to the selection; ifmark is false the selection is cleared.

See alsocursorBackward().

int QLineEdit::cursorPositionAt(constQPoint & pos)

Returns the cursor position under the pointpos.

[signal]void QLineEdit::cursorPositionChanged(int old,int new)

This signal is emitted whenever the cursor moves. The previous position is given byold, and the new position bynew.

See alsosetCursorPosition() andcursorPosition().

[protected]QRect QLineEdit::cursorRect() const

Returns a rectangle that includes the lineedit cursor.

This function was introduced in Qt 4.4.

void QLineEdit::cursorWordBackward(bool mark)

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

See alsocursorWordForward().

void QLineEdit::cursorWordForward(bool mark)

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

See alsocursorWordBackward().

[slot]void QLineEdit::cut()

Copies the selected text to the clipboard and deletes it, if there is any, and ifechoMode() isNormal.

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

See alsocopy(),paste(), andsetValidator().

void QLineEdit::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 alsobackspace().

void QLineEdit::deselect()

Deselects any selected text.

See alsosetSelection() andselectAll().

[virtual protected]void QLineEdit::dragEnterEvent(QDragEnterEvent * e)

Reimplemented fromQWidget::dragEnterEvent().

[virtual protected]void QLineEdit::dragLeaveEvent(QDragLeaveEvent * e)

Reimplemented fromQWidget::dragLeaveEvent().

[virtual protected]void QLineEdit::dragMoveEvent(QDragMoveEvent * e)

Reimplemented fromQWidget::dragMoveEvent().

[virtual protected]void QLineEdit::dropEvent(QDropEvent * e)

Reimplemented fromQWidget::dropEvent().

[signal]void QLineEdit::editingFinished()

This signal is emitted when the Return or Enter key is pressed or the line edit loses focus. Note that if there is avalidator() orinputMask() set on the line edit and enter/return is pressed, the editingFinished() signal will only be emitted if the input follows theinputMask() and thevalidator() returnsQValidator::Acceptable.

void QLineEdit::end(bool mark)

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

See alsohome().

[virtual]bool QLineEdit::event(QEvent * e)

Reimplemented fromQObject::event().

[virtual protected]void QLineEdit::focusInEvent(QFocusEvent * e)

Reimplemented fromQWidget::focusInEvent().

[virtual protected]void QLineEdit::focusOutEvent(QFocusEvent * e)

Reimplemented fromQWidget::focusOutEvent().

void QLineEdit::getTextMargins(int * left,int * top,int * right,int * bottom) const

Returns the widget's text margins forleft,top,right, andbottom.

This function was introduced in Qt 4.5.

See alsosetTextMargins().

void QLineEdit::home(bool mark)

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

See alsoend().

[protected]void QLineEdit::initStyleOption(QStyleOptionFrame * option) const

Initializeoption with the values from thisQLineEdit. This method is useful for subclasses when they need aQStyleOptionFrame orQStyleOptionFrameV2, but don't want to fill in all the information themselves. This function will check the version of theQStyleOptionFrame and fill in the additional values for aQStyleOptionFrameV2.

See alsoQStyleOption::initFrom().

[virtual protected]void QLineEdit::inputMethodEvent(QInputMethodEvent * e)

Reimplemented fromQWidget::inputMethodEvent().

[virtual]QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const

Reimplemented fromQWidget::inputMethodQuery().

void QLineEdit::insert(constQString & newText)

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

See alsosetText() andclear().

[virtual protected]void QLineEdit::keyPressEvent(QKeyEvent * event)

Reimplemented fromQWidget::keyPressEvent().

Converts the given key pressevent into a line edit action.

If Return or Enter is pressed and the current text is valid (or can bemade valid by the validator), the signalreturnPressed() is emitted.

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

[virtual]QSize QLineEdit::minimumSizeHint() const

Reimplemented fromQWidget::minimumSizeHint().

Returns a minimum size for the line edit.

The width returned is enough for at least one character.

[virtual protected]void QLineEdit::mouseDoubleClickEvent(QMouseEvent * e)

Reimplemented fromQWidget::mouseDoubleClickEvent().

[virtual protected]void QLineEdit::mouseMoveEvent(QMouseEvent * e)

Reimplemented fromQWidget::mouseMoveEvent().

[virtual protected]void QLineEdit::mousePressEvent(QMouseEvent * e)

Reimplemented fromQWidget::mousePressEvent().

[virtual protected]void QLineEdit::mouseReleaseEvent(QMouseEvent * e)

Reimplemented fromQWidget::mouseReleaseEvent().

[virtual protected]void QLineEdit::paintEvent(QPaintEvent *)

Reimplemented fromQWidget::paintEvent().

[slot]void QLineEdit::paste()

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

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

See alsocopy() andcut().

[slot]void QLineEdit::redo()

Redoes the last operation if redo isavailable.

[signal]void QLineEdit::returnPressed()

This signal is emitted when the Return or Enter key is pressed. Note that if there is avalidator() orinputMask() set on the line edit, the returnPressed() signal will only be emitted if the input follows theinputMask() and thevalidator() returnsQValidator::Acceptable.

[slot]void QLineEdit::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 alsosetSelection() anddeselect().

[signal]void QLineEdit::selectionChanged()

This signal is emitted whenever the selection changes.

See alsohasSelectedText() andselectedText().

int QLineEdit::selectionStart() const

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

See alsoselectedText().

void QLineEdit::setCompleter(QCompleter * c)

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

To use aQCompleter with aQValidator orQLineEdit::inputMask, you need to ensure that the model provided toQCompleter contains valid entries. You can use theQSortFilterProxyModel to ensure that theQCompleter's model contains only valid entries.

Ifc == 0, setCompleter() removes the current completer, effectively disabling auto completion.

This function was introduced in Qt 4.2.

See alsocompleter() andQCompleter.

void QLineEdit::setSelection(int start,int length)

Selects text from positionstart and forlength characters. Negative lengths are allowed.

See alsodeselect(),selectAll(), andselectedText().

void QLineEdit::setTextMargins(int left,int top,int right,int bottom)

Sets the margins around the text inside the frame to have the sizesleft,top,right, andbottom.

See alsogetTextMargins().

This function was introduced in Qt 4.5.

See alsotextMargins().

void QLineEdit::setTextMargins(constQMargins & margins)

Sets themargins around the text inside the frame.

See alsotextMargins().

This function was introduced in Qt 4.6.

void QLineEdit::setValidator(constQValidator * v)

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

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

See alsovalidator(),QIntValidator,QDoubleValidator, andQRegExpValidator.

[virtual]QSize QLineEdit::sizeHint() const

Reimplemented fromQWidget::sizeHint().

Returns a recommended size for the widget.

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

[signal]void QLineEdit::textEdited(constQString & text)

This signal is emitted whenever the text is edited. Thetext argument is the new text.

UnliketextChanged(), this signal is not emitted when the text is changed programmatically, for example, by callingsetText().

QMargins QLineEdit::textMargins() const

Returns the widget's text margins.

This function was introduced in Qt 4.6.

See alsosetTextMargins().

[slot]void QLineEdit::undo()

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

constQValidator * QLineEdit::validator() const

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

See alsosetValidator().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp