LineEdit

Inherits: Control < CanvasItem < Node < Object

Category: Core

Brief Description

Control that provides single-line string editing.

Properties

Alignalign
boolcaret_blink
floatcaret_blink_speed
intcaret_position
boolclear_button_enabled
boolcontext_menu_enabled
booleditable
boolexpand_to_text_length
FocusModefocus_mode
intmax_length
floatplaceholder_alpha
Stringplaceholder_text
boolsecret
Stringsecret_character
Stringtext

Methods

voidappend_at_cursor ( String text )
voidclear ( )
voiddeselect ( )
PopupMenuget_menu ( ) const
voidmenu_option ( int option )
voidselect ( int from=0, int to=-1 )
voidselect_all ( )

Theme Properties

Textureclear
Colorclear_button_color
Colorclear_button_color_pressed
Colorcursor_color
StyleBoxfocus
Fontfont
Colorfont_color
Colorfont_color_selected
intminimum_spaces
StyleBoxnormal
StyleBoxread_only
Colorselection_color

Signals

  • text_changed ( String new_text )

Emitted when the text changes.


  • text_entered ( String new_text )

Emitted when the user presses KEY_ENTER on the LineEdit.

Enumerations

enum 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.

enum 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).
  • MENU_CLEAR = 3 — Erases the whole LineEdit text.
  • MENU_SELECT_ALL = 4 — Selects the whole LineEdit text.
  • 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.

Description

LineEdit provides a single-line string editor, used for text fields. It features many built-in shortcuts which will always be available:

  • 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

Property Descriptions

Setterset_align(value)
Getterget_align()

Text alignment as defined in the ALIGN_* enum.


Settercursor_set_blink_enabled(value)
Gettercursor_get_blink_enabled()

If true, the caret (visual cursor) blinks.


Settercursor_set_blink_speed(value)
Gettercursor_get_blink_speed()

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


  • int caret_position
Setterset_cursor_position(value)
Getterget_cursor_position()

The cursor’s position inside the LineEdit. When set, the text may scroll to accommodate it.


  • bool clear_button_enabled
Setterset_clear_button_enabled(value)
Getteris_clear_button_enabled()

If true, the LineEdit will show a clear button if text is not empty.


  • bool context_menu_enabled
Setterset_context_menu_enabled(value)
Getteris_context_menu_enabled()

If true, the context menu will appear when right clicked.


Setterset_editable(value)
Getteris_editable()

If false, existing text cannot be modified and new text cannot be added.


  • bool expand_to_text_length
Setterset_expand_to_text_length(value)
Getterget_expand_to_text_length()

If true, the LineEdit width will increase to stay longer than the text. It will not compress if the text is shortened.


Setterset_focus_mode(value)
Getterget_focus_mode()

Defines how the LineEdit can grab focus (Keyboard and mouse, only keyboard, or none). See enum FocusMode in Control for details.


  • int max_length
Setterset_max_length(value)
Getterget_max_length()

Maximum amount of characters that can be entered inside the LineEdit. If 0, there is no limit.


Setterset_placeholder_alpha(value)
Getterget_placeholder_alpha()

Opacity of the placeholder_text. From 0 to 1.


Setterset_placeholder(value)
Getterget_placeholder()

Text shown when the LineEdit is empty. It is not the LineEdit’s default value (see text).


Setterset_secret(value)
Getteris_secret()

If true, every character is replaced with the secret character (see secret_character).


Setterset_secret_character(value)
Getterget_secret_character()

The character to use to mask secret input (defaults to “*”). Only a single character can be used as the secret character.


Setterset_text(value)
Getterget_text()

String value of the LineEdit.

Method Descriptions

  • void append_at_cursor ( String text )

Adds text after the cursor. If the resulting value is longer than max_length, nothing happens.


  • void clear ( )

Erases the LineEdit text.


  • void deselect ( )

Clears the current selection.


Returns the PopupMenu of this LineEdit. By default, this menu is displayed when right-clicking on the LineEdit.


  • void menu_option ( int option )

Executes a given action as defined in the MENU_* enum.


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

Selects characters inside LineEdit between from and to. By default from is at the beginning and to at the end.

  1. text = "Welcome"
  2. select() # Welcome
  3. select(4) # ome
  4. select(2, 5) # lco

  • void select_all ( )

Selects the whole String.