LineEdit

Inherits: Control < CanvasItem < Node < Object

Category: Core

Brief Description

Control that provides single line string editing.

Member Functions

void append_at_cursor ( String text )
void clear ( )
int get_cursor_position ( ) const
PopupMenu get_menu ( ) const
void menu_option ( int option )
void select ( int from=0, int to=-1 )
void select_all ( )
void set_cursor_position ( int position )

Signals

  • text_changed ( String text )

Emitted when the text changes.

  • text_entered ( String text )

Emitted when the user presses KEY_ENTER on the LineEdit.

Member Variables

  • int align - Text alignment as defined in the ALIGN_* enum.
  • bool context_menu_enabled - If true the context menu will appear when right clicked.
  • bool editable - If false existing text cannot be modified and new text cannot be added.
  • bool 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.
  • int 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 - Maximum amount of characters that can be entered inside the LineEdit. If 0, there is no limit.
  • float placeholder_alpha - Opacity of the placeholder_text. From 0 to 1.
  • String placeholder_text - Text shown when the LineEdit is empty. It is not the LineEdit‘s default value (see text).
  • bool secret - If true every character is shown as “*”.
  • String text - String value of the LineEdit.

Numeric Constants

  • 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.
  • 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 Linedit text.
  • MENU_SELECT_ALL = 4 — Selects the whole Linedit text.
  • MENU_UNDO = 5 — Undoes the previous action.
  • MENU_REDO = 6
  • MENU_MAX = 7

Description

LineEdit provides a single line string editor, used for text fields.

Member Function Description

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

  • int get_cursor_position ( ) const

Returns the cursor position inside the LineEdit.

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.

text = "Welcome"
select()     # Welcome
select(4)    # ome
select(2, 5) # lco
  • void select_all ( )

Selects the whole String.

  • void set_cursor_position ( int position )

Sets the cursor position inside the LineEdit. The text may scroll if needed.