LineEdit

    Control that provides single-line string editing.

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

    It features many built-in shortcuts which will always be available ( 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
    • 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

    void ( String text )
    void ( )
    voiddelete_char_at_cursor ( )
    void ( int from_column, to_column )
    voiddeselect ( )
    get_menu ( ) const
    get_scroll_offset ( ) const
    void ( int option )
    void ( int from=0, to=-1 )
    voidselect_all ( )

    Theme Properties

    clear 
    Colorclear_button_colorColor( 0.88, 0.88, 0.88, 1 )
    clear_button_color_pressedColor( 1, 1, 1, 1 )
    Colorcursor_colorColor( 0.94, 0.94, 0.94, 1 )
    focus 
    Fontfont 
    font_colorColor( 0.88, 0.88, 0.88, 1 )
    Colorfont_color_selectedColor( 0, 0, 0, 1 )
    font_color_uneditableColor( 0.88, 0.88, 0.88, 0.5 )
    intminimum_spaces12
    normal 
    StyleBoxread_only 
    selection_colorColor( 0.49, 0.49, 0.49, 1 )
    • text_change_rejected ( )

    Emitted when trying to append text that would overflow the max_length.


    • text_changed ( new_text )

    Emitted when the text changes.


    • text_entered ( String new_text )

    Emitted when the user presses 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).

    Non-printable escape characters are automatically stripped from the OS clipboard via String.strip_escapes.

    • MENU_CLEAR = 3 —- Erases the whole 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 enum.
    Default0
    Setterset_align(value)
    Getterget_align()

    Text alignment as defined in the enum.


    Defaultfalse
    Settercursor_set_blink_enabled(value)
    Gettercursor_get_blink_enabled()

    If true, the caret (visual cursor) blinks.


    • caret_blink_speed
    Default0.65
    Settercursor_set_blink_speed(value)
    Gettercursor_get_blink_speed()

    • int caret_position
    Default0
    Setterset_cursor_position(value)
    Getterget_cursor_position()

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


    • clear_button_enabled

    If true, the LineEdit will show a clear button if text is not empty, which can be used to clear the text quickly.


    Defaulttrue
    Setterset_context_menu_enabled(value)
    Getteris_context_menu_enabled()

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


    Defaulttrue
    Setterset_editable(value)
    Getteris_editable()

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


    • expand_to_text_length
    Defaultfalse
    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 is shortened.


    • int max_length
    Default0
    Setterset_max_length(value)
    Getterget_max_length()

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


    • placeholder_alpha
    Default0.6
    Setterset_placeholder_alpha(value)
    Getterget_placeholder_alpha()

    Opacity of the placeholder_text. From 0 to 1.


    • placeholder_text
    Default“”
    Setterset_placeholder(value)
    Getterget_placeholder()

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


    • right_icon

    Sets the icon that will appear in the right end of the LineEdit if there’s no text, or always, if is set to false.


    Defaultfalse
    Setterset_secret(value)
    Getteris_secret()

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


    Default“*”
    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.


    • selecting_enabled
    Defaulttrue
    Setterset_selecting_enabled(value)
    Getteris_selecting_enabled()

    If false, it’s impossible to select the text using mouse nor keyboard.


    • bool shortcut_keys_enabled
    Defaulttrue
    Setterset_shortcut_keys_enabled(value)
    Getteris_shortcut_keys_enabled()

    • text
    Default“”
    Setterset_text(value)
    Getterget_text()

    String value of the LineEdit.

    Note: Changing text using this property won’t emit the text_changed signal.


    • virtual_keyboard_enabled
    Defaulttrue
    Setterset_virtual_keyboard_enabled(value)
    Getteris_virtual_keyboard_enabled()

    If true, the native virtual keyboard is shown when focused on platforms that support it.

    Method Descriptions

    • void append_at_cursor ( String text )

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


    • void clear ( )

    Erases the LineEdit‘s text.


    • void delete_char_at_cursor ( )

    Deletes one character at the cursor’s current position (equivalent to pressing the Delete key).


    • void delete_text ( from_column, int to_column )

    Deletes a section of the going from position from_column to to_column. Both parameters should be within the text’s length.


    • void deselect ( )

    Clears the current selection.


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


    • int get_scroll_offset ( ) const

    Returns the scroll offset due to , as a number of characters.


    • void menu_option ( int option )

    Executes a given action as defined in the enum.


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

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


    • void select_all ( )