Up to date

This page is up to date for Godot 4.0. If you still find outdated information, please open an issue.

LineEdit

Inherits: Control < CanvasItem < Node < Object

An input field for single-line text.

Description

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):

  • Ctrl + C: Copy

  • Ctrl + X: Cut

  • Ctrl + V or Ctrl + Y: Paste/"yank"

  • Ctrl + Z: Undo

  • Ctrl + ~: Swap input direction.

  • Ctrl + Shift + Z: Redo

  • Ctrl + U: Delete text from the caret position to the beginning of the line

  • Ctrl + K: Delete text from the caret position to the end of the line

  • Ctrl + A: Select all text

  • Up Arrow/Down Arrow: Move the caret to the beginning/end of the line

On macOS, some extra keyboard shortcuts are available:

  • Cmd + F: Same as Right Arrow, move the caret one character right

  • Cmd + B: Same as Left Arrow, move the caret one character left

  • Cmd + P: Same as Up Arrow, move the caret to the previous line

  • Cmd + N: Same as Down Arrow, move the caret to the next line

  • Cmd + D: Same as Delete, delete the character on the right side of caret

  • Cmd + H: Same as Backspace, delete the character on the left side of the caret

  • Cmd + A: Same as Home, move the caret to the beginning of the line

  • Cmd + E: Same as End, move the caret to the end of the line

  • Cmd + Left Arrow: Same as Home, move the caret to the beginning of the line

  • Cmd + Right Arrow: Same as End, move the caret to the end of the line

Properties

HorizontalAlignment

alignment

0

bool

caret_blink

false

float

caret_blink_interval

0.65

int

caret_column

0

bool

caret_force_displayed

false

bool

caret_mid_grapheme

true

bool

clear_button_enabled

false

bool

context_menu_enabled

true

bool

deselect_on_focus_loss_enabled

true

bool

draw_control_chars

false

bool

editable

true

bool

expand_to_text_length

false

bool

flat

false

FocusMode

focus_mode

2 (overrides Control)

String

language

""

int

max_length

0

bool

middle_mouse_paste_enabled

true

CursorShape

mouse_default_cursor_shape

1 (overrides Control)

String

placeholder_text

""

Texture2D

right_icon

bool

secret

false

String

secret_character

"•"

bool

select_all_on_focus

false

bool

selecting_enabled

true

bool

shortcut_keys_enabled

true

StructuredTextParser

structured_text_bidi_override

0

Array

structured_text_bidi_override_options

[]

String

text

""

TextDirection

text_direction

0

bool

virtual_keyboard_enabled

true

VirtualKeyboardType

virtual_keyboard_type

0

Methods

void

clear ( )

void

delete_char_at_caret ( )

void

delete_text ( int from_column, int to_column )

void

deselect ( )

PopupMenu

get_menu ( ) const

float

get_scroll_offset ( ) const

int

get_selection_from_column ( ) const

int

get_selection_to_column ( ) const

bool

has_selection ( ) const

void

insert_text_at_caret ( String text )

bool

is_menu_visible ( ) const

void

menu_option ( int option )

void

select ( int from=0, int to=-1 )

void

select_all ( )

Theme Properties

Color

caret_color

Color(0.95, 0.95, 0.95, 1)

Color

clear_button_color

Color(0.875, 0.875, 0.875, 1)

Color

clear_button_color_pressed

Color(1, 1, 1, 1)

Color

font_color

Color(0.875, 0.875, 0.875, 1)

Color

font_outline_color

Color(1, 1, 1, 1)

Color

font_placeholder_color

Color(0.875, 0.875, 0.875, 0.6)

Color

font_selected_color

Color(1, 1, 1, 1)

Color

font_uneditable_color

Color(0.875, 0.875, 0.875, 0.5)

Color

selection_color

Color(0.5, 0.5, 0.5, 1)

int

caret_width

1

int

minimum_character_width

4

int

outline_size

0

Font

font

int

font_size

Texture2D

clear

StyleBox

focus

StyleBox

normal

StyleBox

read_only


Signals

text_change_rejected ( String rejected_substring )

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.


text_changed ( String new_text )

Emitted when the text changes.


text_submitted ( String new_text )

Emitted when the user presses @GlobalScope.KEY_ENTER on the LineEdit.


Enumerations

enum MenuItems:

MenuItems MENU_CUT = 0

Cuts (copies and clears) the selected text.

MenuItems MENU_COPY = 1

Copies the selected text.

MenuItems MENU_PASTE = 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.

MenuItems MENU_CLEAR = 3

Erases the whole LineEdit text.

MenuItems MENU_SELECT_ALL = 4

Selects the whole LineEdit text.

MenuItems MENU_UNDO = 5

Undoes the previous action.

MenuItems MENU_REDO = 6

Reverse the last undo action.

MenuItems MENU_SUBMENU_TEXT_DIR = 7

ID of "Text Writing Direction" submenu.

MenuItems MENU_DIR_INHERITED = 8

Sets text direction to inherited.

MenuItems MENU_DIR_AUTO = 9

Sets text direction to automatic.

MenuItems MENU_DIR_LTR = 10

Sets text direction to left-to-right.

MenuItems MENU_DIR_RTL = 11

Sets text direction to right-to-left.

MenuItems MENU_DISPLAY_UCC = 12

Toggles control character display.

MenuItems MENU_SUBMENU_INSERT_UCC = 13

ID of "Insert Control Character" submenu.

MenuItems MENU_INSERT_LRM = 14

Inserts left-to-right mark (LRM) character.

MenuItems MENU_INSERT_RLM = 15

Inserts right-to-left mark (RLM) character.

MenuItems MENU_INSERT_LRE = 16

Inserts start of left-to-right embedding (LRE) character.

MenuItems MENU_INSERT_RLE = 17

Inserts start of right-to-left embedding (RLE) character.

MenuItems MENU_INSERT_LRO = 18

Inserts start of left-to-right override (LRO) character.

MenuItems MENU_INSERT_RLO = 19

Inserts start of right-to-left override (RLO) character.

MenuItems MENU_INSERT_PDF = 20

Inserts pop direction formatting (PDF) character.

MenuItems MENU_INSERT_ALM = 21

Inserts Arabic letter mark (ALM) character.

MenuItems MENU_INSERT_LRI = 22

Inserts left-to-right isolate (LRI) character.

MenuItems MENU_INSERT_RLI = 23

Inserts right-to-left isolate (RLI) character.

MenuItems MENU_INSERT_FSI = 24

Inserts first strong isolate (FSI) character.

MenuItems MENU_INSERT_PDI = 25

Inserts pop direction isolate (PDI) character.

MenuItems MENU_INSERT_ZWJ = 26

Inserts zero width joiner (ZWJ) character.

MenuItems MENU_INSERT_ZWNJ = 27

Inserts zero width non-joiner (ZWNJ) character.

MenuItems MENU_INSERT_WJ = 28

Inserts word joiner (WJ) character.

MenuItems MENU_INSERT_SHY = 29

Inserts soft hyphen (SHY) character.

MenuItems MENU_MAX = 30

Represents the size of the MenuItems enum.


enum VirtualKeyboardType:

VirtualKeyboardType KEYBOARD_TYPE_DEFAULT = 0

Default text virtual keyboard.

VirtualKeyboardType KEYBOARD_TYPE_MULTILINE = 1

Multiline virtual keyboard.

VirtualKeyboardType KEYBOARD_TYPE_NUMBER = 2

Virtual number keypad, useful for PIN entry.

VirtualKeyboardType KEYBOARD_TYPE_NUMBER_DECIMAL = 3

Virtual number keypad, useful for entering fractional numbers.

VirtualKeyboardType KEYBOARD_TYPE_PHONE = 4

Virtual phone number keypad.

VirtualKeyboardType KEYBOARD_TYPE_EMAIL_ADDRESS = 5

Virtual keyboard with additional keys to assist with typing email addresses.

VirtualKeyboardType KEYBOARD_TYPE_PASSWORD = 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.

VirtualKeyboardType KEYBOARD_TYPE_URL = 7

Virtual keyboard with additional keys to assist with typing URLs.


Property Descriptions

HorizontalAlignment alignment = 0

Text alignment as defined in the HorizontalAlignment enum.


  • void set_caret_blink_enabled ( bool value )

  • bool is_caret_blink_enabled ( )

If true, the caret (text cursor) blinks.


  • void set_caret_blink_interval ( float value )

  • float get_caret_blink_interval ( )

Duration (in seconds) of a caret's blinking cycle.


int caret_column = 0

  • void set_caret_column ( int value )

  • int get_caret_column ( )

The caret's column position inside the LineEdit. When set, the text may scroll to accommodate it.


bool caret_force_displayed = false

  • void set_caret_force_displayed ( bool value )

  • bool is_caret_force_displayed ( )

If true, the LineEdit will always show the caret, even if focus is lost.


bool caret_mid_grapheme = true

  • void set_caret_mid_grapheme_enabled ( bool value )

  • bool is_caret_mid_grapheme_enabled ( )

Allow moving caret, selecting and removing the individual composite character components.

Note: Backspace is always removing individual composite character components.


bool clear_button_enabled = false

  • void set_clear_button_enabled ( bool value )

  • bool is_clear_button_enabled (