LineEdit
Inherits: Control < CanvasItem < Node < Object Control that provides single-line string editing.
Description
LineEdit provides a single-line string editor, used for text fields.
Ctrl here maps to Command on macOS):
- Ctrl + C: Copy
- Ctrl + X: Cut
- Ctrl + V or Ctrl + Y: Paste/“yank”
- Ctrl + Z: Undo
- Ctrl + Shift + Z: Redo
- Ctrl + U: Delete text from the cursor position to the beginning of the line
- Ctrl + K: Delete text from the cursor position to the end of the line
- Ctrl + A: Select all text
- Up/Down arrow: Move the cursor to the beginning/end of the line On macOS, some extra keyboard shortcuts are available:
- Ctrl + F: Like the right arrow key, move the cursor one character right
- Ctrl + B: Like the left arrow key, move the cursor one character left
- Ctrl + P: Like the up arrow key, move the cursor to the previous line
- Ctrl + N: Like the down arrow key, move the cursor to the next line
- Ctrl + D: Like the Delete key, delete the character on the right side of cursor
- Ctrl + H: Like the Backspace key, delete the character on the left side of the cursor
- Command + Left arrow: Like the Home key, move the cursor to the beginning of the line
- Command + Right arrow: Like the End key, move the cursor to the end of the line
Properties
Methods
Theme Properties
Signals
- text_change_rejected ( String rejected_substring )
max_length. The appended text is truncated to fit max_length, and the part that couldn’t fit is passed as the
rejected_substringargument.
- text_changed ( String new_text ) Emitted when the text changes.
- text_entered ( String new_text )
@GlobalScope.KEY_ENTER on the
LineEdit.Enumerations
Align: - ALIGN_LEFT = 0 —- Aligns the text on the left-hand side of the
LineEdit. - ALIGN_CENTER = 1 —- Centers the text in the middle of the
LineEdit. - ALIGN_RIGHT = 2 —- Aligns the text on the right-hand side of the
LineEdit. - ALIGN_FILL = 3 —- Stretches whitespaces to fit the
LineEdit‘s width.
MenuItems:
- MENU_CUT = 0 —- Cuts (copies and clears) the selected text.
- MENU_COPY = 1 —- Copies the selected text.
- MENU_PASTE = 2 —- Pastes the clipboard text over the selected text (or at the cursor’s position). String.strip_escapes.
- MENU_CLEAR = 3 —- Erases the whole
LineEdittext. - MENU_SELECT_ALL = 4 —- Selects the whole
LineEdittext. - MENU_UNDO = 5 —- Undoes the previous action.
- MENU_REDO = 6 —- Reverse the last undo action.
- MENU_MAX = 7 —- Represents the size of the MenuItems enum.
Property Descriptions
- Align align Align enum.
- bool caret_blink
true, the caret (visual cursor) blinks.
- float caret_blink_speed Duration (in seconds) of a caret’s blinking cycle.
- int caret_position
LineEdit. When set, the text may scroll to accommodate it.
- bool clear_button_enabled
true, theLineEditwill show a clear button iftextis not empty, which can be used to clear the text quickly.
- bool context_menu_enabled
true, the context menu will appear when right-clicked.
- bool deselect_on_focus_loss_enabled
true, the selected text will be deselected when focus is lost.
- bool editable
false, existing text cannot be modified and new text cannot be added.
- bool expand_to_text_length
true, theLineEditwidth will increase to stay longer than the text. It will not compress if the text is shortened.
- int max_length
LineEdit. If0, there is no limit. max_length are truncated. This happens both for existing text contents when setting the max length, or for new text inserted in theLineEdit, including pasting. If any input text is truncated, the text_change_rejected signal is emitted with the truncated substring as parameter. Example:text = "Hello world"max_length = 5# `text` becomes "Hello".max_length = 10text += " goodbye"# `text` becomes "Hello good".# `text_change_rejected` is emitted with "bye" as parameter.
- bool middle_mouse_paste_enabled
false, using middle mouse button to paste clipboard will be disabled. Note: This method is only implemented on Linux.
- float placeholder_alpha
placeholder_text. From
0to1.
- String placeholder_text
LineEditis empty. It is not theLineEdit‘s default value (see text).
- Texture right_icon
LineEditif there’s no text, or always, if clear_button_enabled is set tofalse.
- bool secret
true, every character is replaced with the secret character (see secret_character).
- String secret_character The character to use to mask secret input (defaults to “*“). Only a single character can be used as the secret character.
- bool selecting_enabled
false, it’s impossible to select the text using mouse nor keyboard.
- bool shortcut_keys_enabled
false, using shortcuts will be disabled.
- String text
LineEdit. Note: Changing text using this property won’t emit the text_changed signal.
- bool virtual_keyboard_enabled
true, the native virtual keyboard is shown when focused on platforms that support it.Method Descriptions
- append_at_cursor ( String text )
textafter the cursor. If the resulting value is longer than max_length, nothing happens.
- clear ( )
LineEdit‘s text.
- delete_char_at_cursor ( )
Deletekey).
- delete_text ( int from_column, int to_column )
text going from position
from_columntoto_column. Both parameters should be within the text’s length.
- deselect ( ) Clears the current selection.
- PopupMenu get_menu ( ) const
PopupMenu of this
LineEdit. By default, this menu is displayed when right-clicking on theLineEdit. Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their CanvasItem.visible property.
- int get_scroll_offset ( ) const caret_position, as a number of characters.
- int get_selection_from_column ( ) const Returns the selection begin column.
- int get_selection_to_column ( ) const Returns the selection end column.
- bool has_selection ( ) const
trueif the user has selected text.
- menu_option ( int option ) MenuItems enum.
- select ( int from=0, int to=-1 )
LineEditbetweenfromandto. By default,fromis at the beginning andtoat the end.text = "Welcome"select() # Will select "Welcome".select(4) # Will select "ome".select(2, 5) # Will select "lco".
- select_all ( )
String.
Theme Property Descriptions
- Color clear_button_color Color used as default tint for the clear button.
- Color clear_button_color_pressed Color used for the clear button when it’s pressed.
- Color cursor_color
LineEdit‘s visual cursor (caret).
- Color font_color Default font color.
- Color font_color_selected Font color for selected text (inside the selection rectangle).
- Color font_color_uneditable Font color when editing is disabled.
- Color selection_color Color of the selection rectangle.
- int minimum_spaces Minimum horizontal space for the text (not counting the clear button and content margins). This value is measured in count of space characters (i.e. this amount of space characters can be displayed without scrolling).
- Font font Font used for the text.
- Texture clear clear_button_enabled.
- StyleBox focus
LineEdithas GUI focus.
- StyleBox normal
LineEdit.
- StyleBox read_only
LineEditis in read-only mode (editable is set tofalse).
