Inherits: Control < CanvasItem < Node < Object
An input field for single-line text.
LineEdit provides an input field for editing a single line of text. It features many built-in shortcuts that are always available (Ctrl here maps to Cmd on macOS):
On macOS, some extra keyboard shortcuts are available:
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
focus_mode |
| |
| ||
| ||
| ||
mouse_default_cursor_shape |
| |
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
|
void | clear ( ) |
void | |
void | delete_text ( int from_column, int to_column ) |
void | deselect ( ) |
get_menu ( ) const | |
get_scroll_offset ( ) const | |
get_selection_from_column ( ) const | |
get_selection_to_column ( ) const | |
has_selection ( ) const | |
void | insert_text_at_caret ( String text ) |
is_menu_visible ( ) const | |
void | menu_option ( int option ) |
void | |
void | select_all ( ) |
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
Emitted when appending text that overflows the max_length. The appended text is truncated to fit max_length, and the part that couldn't fit is passed as the rejected_substring argument.
Emitted when the text changes.
Emitted when the user presses @GlobalScope.KEY_ENTER on the LineEdit.
0
Cuts (copies and clears) the selected text.
1
Copies the selected text.
2
Pastes the clipboard text over the selected text (or at the caret's position).
Non-printable escape characters are automatically stripped from the OS clipboard via String.strip_escapes.
3
Erases the whole LineEdit text.
4
Selects the whole LineEdit text.
5
Undoes the previous action.
6
Reverse the last undo action.
7
ID of "Text Writing Direction" submenu.
8
Sets text direction to inherited.
9
Sets text direction to automatic.
10
Sets text direction to left-to-right.
11
Sets text direction to right-to-left.
12
Toggles control character display.
13
ID of "Insert Control Character" submenu.
14
Inserts left-to-right mark (LRM) character.
15
Inserts right-to-left mark (RLM) character.
16
Inserts start of left-to-right embedding (LRE) character.
17
Inserts start of right-to-left embedding (RLE) character.
18
Inserts start of left-to-right override (LRO) character.
19
Inserts start of right-to-left override (RLO) character.
20
Inserts pop direction formatting (PDF) character.
21
Inserts Arabic letter mark (ALM) character.
22
Inserts left-to-right isolate (LRI) character.
23
Inserts right-to-left isolate (RLI) character.
24
Inserts first strong isolate (FSI) character.
25
Inserts pop direction isolate (PDI) character.
26
Inserts zero width joiner (ZWJ) character.
27
Inserts zero width non-joiner (ZWNJ) character.
28
Inserts word joiner (WJ) character.
29
Inserts soft hyphen (SHY) character.
30
Represents the size of the MenuItems enum.
0
Default text virtual keyboard.
1
Multiline virtual keyboard.
2
Virtual number keypad, useful for PIN entry.
3
Virtual number keypad, useful for entering fractional numbers.
4
Virtual phone number keypad.
5
Virtual keyboard with additional keys to assist with typing email addresses.
6
Virtual keyboard for entering a password. On most platforms, this should disable autocomplete and autocapitalization.
Note: This is not supported on Web. Instead, this behaves identically to KEYBOARD_TYPE_DEFAULT.
7
Virtual keyboard with additional keys to assist with typing URLs.
0
Text alignment as defined in the HorizontalAlignment enum.
false
If true, makes the caret blink.
0.65
The interval at which the caret blinks (in seconds).
0
The caret's column position inside the LineEdit. When set, the text may scroll to accommodate it.
false
If true, the LineEdit will always show the caret, even if focus is lost.
false
Allow moving caret, selecting and removing the individual composite character components.
Note: Backspace is always removing individual composite character components.
false
If true, the LineEdit will show a clear button if text is not empty, which can be used to clear the text quickly.
true
If true, the context menu will appear when right-clicked.
true
If true, the selected text will be deselected when focus is lost.
true
If true, allow drag and drop of selected text.
false
If true, control characters are displayed.
true
If false, existing text cannot be modified and new text cannot be added.
false
If true, the LineEdit width will increase to stay longer than the text. It will not compress if the text is shortened.
false
If true, the LineEdit doesn't display decoration.
""
Language code used for line-breaking and text shaping algorithms. If left empty, current locale is used instead.
0
Maximum number of characters that can be entered inside the LineEdit. If 0, there is no limit.
When a limit is defined, characters that would exceed max_length are truncated. This happens both for existing text contents when setting the max length, or for new text inserted in the LineEdit, 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 = 10 text += " goodbye" # `text` becomes "Hello good". # `text_change_rejected` is emitted with "bye" as parameter.C#
Text = "Hello world"; MaxLength = 5; // `Text` becomes "Hello". MaxLength = 10; Text += " goodbye"; // `Text` becomes "Hello good". // `text_change_rejected` is emitted with "bye" as parameter.
true
If false, using middle mouse button to paste clipboard will be disabled.
Note: This method is only implemented on Linux.
""
Text shown when the LineEdit is empty. It is not the LineEdit's default value (see text).
Sets the icon that will appear in the right end of the LineEdit if there's no text, or always, if clear_button_enabled is set to false.
false
If true, every character is replaced with the secret character (see secret_character).
"•"
The character to use to mask secret input. Only a single character can be used as the secret character. If it is longer than one character, only the first one will be used. If it is empty, a space will be used instead.
false
If true, the LineEdit will select the whole text when it gains focus.
true
If false, it's impossible to select the text using mouse nor keyboard.
true
If false, using shortcuts will be disabled.
0
Set BiDi algorithm override for the structured text.
[]
Set additional options for BiDi override.
""
String value of the LineEdit.
Note: Changing text using this property won't emit the text_changed signal.
0
Base text writing direction.
true
If true, the native virtual keyboard is shown when focused on platforms that support it.
0
Specifies the type of virtual keyboard to show.
Erases the LineEdit's text.
Deletes one character at the caret's current position (equivalent to pressing Delete).
Deletes a section of the text going from position from_column to to_column. Both parameters should be within the text's length.
Clears the current selection.
Returns the PopupMenu of this LineEdit. By default, this menu is displayed when right-clicking on the LineEdit.
You can add custom menu items or remove standard ones. Make sure your IDs don't conflict with the standard ones (see MenuItems). For example:
func _ready():
var menu = get_menu()
# Remove all items after "Redo".
menu.item_count = menu.get_item_index(MENU_REDO) + 1
# Add custom items.
menu.add_separator()
menu.add_item("Insert Date", MENU_MAX + 1)
# Connect callback.
menu.id_pressed.connect(_on_item_pressed)
func _on_item_pressed(id):
if id == MENU_MAX + 1:
insert_text_at_caret(Time.get_date_string_from_system())
C#public override void _Ready()
{
var menu = GetMenu();
// Remove all items after "Redo".
menu.ItemCount = menu.GetItemIndex(LineEdit.MenuItems.Redo) + 1;
// Add custom items.
menu.AddSeparator();
menu.AddItem("Insert Date", LineEdit.MenuItems.Max + 1);
// Add event handler.
menu.IdPressed += OnItemPressed;
}
public void OnItemPressed(int id)
{
if (id == LineEdit.MenuItems.Max + 1)
{
InsertTextAtCaret(Time.GetDateStringFromSystem());
}
}
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 Window.visible property.
Returns the scroll offset due to caret_column, as a number of characters.
Returns the text inside the selection.
Returns the selection begin column.
Returns the selection end column.
Returns true if the user has selected text.
Inserts text at the caret. If the resulting value is longer than max_length, nothing happens.
Returns whether the menu is visible. Use this instead of get_menu().visible to improve performance (so the creation of the menu is avoided).
Executes a given action as defined in the MenuItems enum.
Selects characters inside LineEdit between from and to. By default, from is at the beginning and to at the end.
text = "Welcome" select() # Will select "Welcome". select(4) # Will select "ome". select(2, 5) # Will select "lco".C#
Text = "Welcome"; Select(); // Will select "Welcome". Select(4); // Will select "ome". Select(2, 5); // Will select "lco".
Selects the whole String.
Color(0.95, 0.95, 0.95, 1)
Color of the LineEdit's caret (text cursor). This can be set to a fully transparent color to hide the caret entirely.
Color(0.875, 0.875, 0.875, 1)
Color used as default tint for the clear button.
Color(1, 1, 1, 1)
Color used for the clear button when it's pressed.
Color(0.875, 0.875, 0.875, 1)
Default font color.
Color(1, 1, 1, 1)
The tint of text outline of the LineEdit.
Color(0.875, 0.875, 0.875, 0.6)
Font color for placeholder_text.
Color(1, 1, 1, 1)
Font color for selected text (inside the selection rectangle).
Color(0.875, 0.875, 0.875, 0.5)
Font color when editing is disabled.
Color(0.5, 0.5, 0.5, 1)
Color of the selection rectangle.
1
The caret's width in pixels. Greater values can be used to improve accessibility by ensuring the caret is easily visible, or to ensure consistency with a large font size.
4
Minimum horizontal space for the text (not counting the clear button and content margins). This value is measured in count of 'M' characters (i.e. this number of 'M' characters can be displayed without scrolling).
0
The size of the text outline.
Note: If using a font with FontFile.multichannel_signed_distance_field enabled, its FontFile.msdf_pixel_range must be set to at least twice the value of outline_size for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.
Font used for the text.
Font size of the LineEdit's text.
Texture for the clear button. See clear_button_enabled.
Background used when LineEdit has GUI focus. The focus StyleBox is displayed over the base StyleBox, so a partially transparent StyleBox should be used to ensure the base StyleBox remains visible. A StyleBox that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a StyleBoxEmpty resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.
Default background for the LineEdit.
Background used when LineEdit is in read-only mode (editable is set to false).
© 2014–present Juan Linietsky, Ariel Manzur and the Godot community
Licensed under the Creative Commons Attribution Unported License v3.0.
https://docs.godotengine.org/en/4.2/classes/class_lineedit.html