Struct rute::auto::line_edit::LineEdit

source ·
pub struct LineEdit<'a> { /* private fields */ }
Expand description

Notice these docs are heavy WIP and not very relevent yet

windows-lineedit.png

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 (see setDragEnabled())..)

By changing the echoMode() of a line edit, it can also be used as a 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. 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 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(), copy()ied and paste()d. 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 platform 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.

  • Keypress
  • Action
  • Left Arrow
  • Moves the cursor one character to the left.
  • Shift+Left Arrow
  • Moves and selects text one character to the left.
  • Right Arrow
  • Moves the cursor one character to the right.
  • Shift+Right Arrow
  • Moves and selects text one character to the right.
  • Home
  • Moves the cursor to the beginning of the line.
  • End
  • Moves the cursor to the end of the line.
  • Backspace
  • Deletes the character to the left of the cursor.
  • Ctrl+Backspace
  • Deletes the word to the left of the cursor.
  • Delete
  • Deletes the character to the right of the cursor.
  • Ctrl+Delete
  • Deletes the word to the right of the cursor.
  • Ctrl+A
  • Select all.
  • Ctrl+C
  • Copies the selected text to the clipboard.
  • Ctrl+Insert
  • Copies the selected text to the clipboard.
  • Ctrl+K
  • Deletes to the end of the line.
  • Ctrl+V
  • Pastes the clipboard text into line edit.
  • Shift+Insert
  • Pastes the clipboard text into line edit.
  • Ctrl+X
  • Deletes the selected text and copies it to the clipboard.
  • Shift+Delete
  • Deletes the selected text and copies it to the clipboard.
  • Ctrl+Z
  • Undoes the last operation.
  • Ctrl+Y
  • Redoes the last undone operation.

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

See also: [TextEdit] [Label] [ComboBox] {fowler}{GUI Design Handbook: Field Entry} {Line Edits Example}

Licence

The documentation is an adoption of the original Qt Documentation and provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.

Implementations

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

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

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

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

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.

By default, this property contains an empty string.

See also: [insert()] [clear()]

Returns the widget’s text margins.

See also: [set_text_margins()]

If echoMode is Normal this returns the same as text(); if EchoMode is Password or PasswordEchoOnEdit it returns a string of platform-dependent password mask characters text().length() in size, e.g. ; if EchoMode is NoEcho returns an empty string, .

By default, this property contains an empty string.

See also: [set_echo_mode()] [text()] EchoMode

Setting this property makes the line edit display a grayed-out placeholder text as long as the line edit is empty.

Normally, an empty line edit shows the placeholder text even when it has focus. However, if the content is horizontally centered, the placeholder text is not displayed under the cursor when the line edit has focus.

By default, this property contains an empty string.

See also: [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.

See also: inputMask

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

The most common setting is Normal, in which the text entered by the user is displayed verbatim, but QLineEdit also supports modes that allow the entered text to be suppressed or obscured: these include NoEcho,

Password and PasswordEchoOnEdit.

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

By default, this property is set to Normal.

See also: EchoMode [display_text()]

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

See also: [set_cursor_position()] [cursor_position()]

Setting the cursor position causes a repaint when appropriate.

By default, this property contains a value of 0.

Returns the cursor position under the point pos.

Returns the cursor position under the point pos.

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

By default, this property contains a combination of Qt::AlignLeft and Qt::AlignVCenter.

See also: [t::alignment()]

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: [cursor_backward()]

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: [cursor_forward()]

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

See also: [cursor_word_backward()]

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

See also: [cursor_word_forward()]

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()]

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()]

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()]

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()]

Selects text from position start and for length characters. Negative lengths are allowed.

See also: [deselect()] [select_all()] [selected_text()]

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.

See also: [selected_text()]

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

By default, this property contains an empty string.

See also: [has_selected_text()]

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

See also: [selected_text()] See also: [selection_end()] See also: [selection_length()]

Returns the index of the character directly after the selection in the line edit or -1 if no text is selected.

See also: [selected_text()] See also: [selection_start()] See also: [selection_length()]

Returns the length of the selection.

See also: [selected_text()] See also: [selection_start()] See also: [selection_end()]

Dragging is disabled by default.

When this property is set to Qt::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 is Qt::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.

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 (“”).

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 is permitted but not required .

  • Character
  • Meaning
  • A
  • ASCII alphabetic character required. A-Z, a-z.
  • a
  • ASCII alphabetic character permitted but not required.
  • N
  • ASCII alphanumeric character required. A-Z, a-z, 0-9.
  • n
  • ASCII alphanumeric character permitted but not required.
  • X
  • Any character required.
  • x
  • Any character permitted but not required.
  • 9
  • ASCII digit required. 0-9.
  • 0
  • ASCII digit permitted but not required.
  • D
  • ASCII digit required. 1-9.
  • d
  • ASCII digit permitted but not required (1-9).
  • #
  • ASCII digit or plus/minus sign permitted but not required.
  • H
  • Hexadecimal character required. A-F, a-f, 0-9.
  • h
  • Hexadecimal character permitted but not required.
  • B
  • Binary character required. 0-1.
  • b
  • Binary character permitted but not required.
  • >
  • All following alphabetic characters are uppercased.
  • <
  • All following alphabetic characters are lowercased.
  • !
  • Switch off case conversion.
  • [ ] { }
  • Reserved.
  • \\
  • 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:

  • Mask
  • Notes
  • 000.000.000.000;_
  • IP address; blanks are _ .
  • HH:HH:HH:HH:HH:HH;_
  • MAC address
  • 0000-00-00
  • ISO 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: maxLength

Sets the margins around the text inside the frame to have the sizes left, top, right, and bottom.

See also getTextMargins().

Sets the margins around the text inside the frame.

See also textMargins().

Sets the margins around the text inside the frame to have the sizes left, top, right, and bottom.

See also getTextMargins().

Sets the margins around the text inside the frame.

See also textMargins().

Returns the widget’s text margins.

See also: [set_text_margins()]

Sets the margins around the text inside the frame to have the sizes left, top, right, and bottom.

See also getTextMargins().

Sets the margins around the text inside the frame.

See also textMargins().

If enabled, the line edit displays a trailing clear button when it contains some text, otherwise the line edit does not show a clear button (the default).

See also: [add_action()] [remove_action()]

Clears the contents of the line edit.

See also: [set_text()] [insert()]

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: [set_selection()] [deselect()]

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

By default, this property is false.

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

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.

Redoes the last operation if redo is available

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()] [set_validator()]

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

See also: [cut()] [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()]

Deselects any selected text.

See also: [set_selection()] [select_all()]

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

See also: [set_text()] [clear()]

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

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

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

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

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

See also: [set_cursor_position()] [cursor_position()]

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.

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.

This signal is emitted whenever the selection changes.

See also: [has_selected_text()] [selected_text()]

Converts the given key press event 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.

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.

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

See also: [set_context_menu_policy()]

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.