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

    • Ctrl + H: Like the Backspace key, delete the character on the left side of the 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

    Methods

    void

    ( String text )

    void

    ( )

    void

    delete_char_at_cursor ( )

    void

    ( int from_column, 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

    ( int option )

    void

    ( int from=0, to=-1 )

    void

    select_all ( )

    Color

    Color( 0.88, 0.88, 0.88, 1 )

    clear_button_color_pressed

    Color( 1, 1, 1, 1 )

    cursor_color

    Color( 0.94, 0.94, 0.94, 1 )

    font_color

    Color( 0.88, 0.88, 0.88, 1 )

    font_color_selected

    Color( 0, 0, 0, 1 )

    font_color_uneditable

    Color( 0.88, 0.88, 0.88, 0.5 )

    selection_color

    Color( 0.49, 0.49, 0.49, 1 )

    minimum_spaces

    12

    font

    clear

    focus

    normal

    read_only

    Signals

    • text_change_rejected ( String rejected_substring )

    Emitted when appending text that overflows the . 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 ( new_text )

    Emitted when the text changes.


    • text_entered ( String new_text )

    Emitted when the user presses on the LineEdit.

    Enumerations

    enum Align:

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

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

    Default

    0

    Setter

    set_align(value)

    Getter

    get_align()

    Text alignment as defined in the enum.


    Default

    false

    Setter

    cursor_set_blink_enabled(value)

    Getter

    cursor_get_blink_enabled()

    If true, the caret (visual cursor) blinks.


    • caret_blink_speed

    Default

    0.65

    Setter

    cursor_set_blink_speed(value)

    Getter

    cursor_get_blink_speed()

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


    • int caret_position

    Default

    0

    Setter

    set_cursor_position(value)

    Getter

    get_cursor_position()

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


    • clear_button_enabled

    Default

    false

    Setter

    set_clear_button_enabled(value)

    Getter

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


    • bool context_menu_enabled

    Default

    true

    Setter

    set_context_menu_enabled(value)

    Getter

    is_context_menu_enabled()

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


    • deselect_on_focus_loss_enabled

    Default

    true

    Setter

    set_deselect_on_focus_loss_enabled(value)

    Getter

    is_deselect_on_focus_loss_enabled()

    If true, the selected text will be deselected when focus is lost.


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


    • expand_to_text_length

    Default

    false

    Setter

    set_expand_to_text_length(value)

    Getter

    get_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

    Default

    0

    Setter

    set_max_length(value)

    get_max_length()

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

    When a limit is defined, characters that would exceed 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 signal is emitted with the truncated substring as parameter.

    Example:


    • bool middle_mouse_paste_enabled

    Default

    true

    Setter

    set_middle_mouse_paste_enabled(value)

    Getter

    is_middle_mouse_paste_enabled()

    If false, using middle mouse button to paste clipboard will be disabled.

    Note: This method is only implemented on Linux.


    • placeholder_alpha

    Default

    0.6

    Setter

    set_placeholder_alpha(value)

    Getter

    get_placeholder_alpha()

    Opacity of the placeholder_text. From 0 to 1.


    • placeholder_text

    Default

    “”

    Setter

    set_placeholder(value)

    Getter

    get_placeholder()

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


    • right_icon

    Setter

    set_right_icon(value)

    Getter

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


    Default

    false

    Setter

    set_secret(value)

    Getter

    is_secret()

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


    Default

    Setter

    set_secret_character(value)

    Getter

    get_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

    Default

    true

    Setter

    set_selecting_enabled(value)

    Getter

    is_selecting_enabled()

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


    • bool shortcut_keys_enabled

    If false, using shortcuts will be disabled.


    Default

    “”

    Setter

    set_text(value)

    Getter

    get_text()

    String value of the LineEdit.

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


    • bool virtual_keyboard_enabled

    Default

    true

    Setter

    set_virtual_keyboard_enabled(value)

    Getter

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

    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 CanvasItem.visible property.


    • get_scroll_offset ( ) const

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


    • get_selection_from_column ( ) const

    Returns the selection begin column.


    • int get_selection_to_column ( ) const

    Returns the selection end column.


    • has_selection ( ) const

    Returns true if the user has selected text.


    • 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 to at the end.

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

    • void select_all ( )

    Selects the whole String.

    Theme Property Descriptions

    • Color clear_button_color

    Default

    Color( 0.88, 0.88, 0.88, 1 )

    Color used as default tint for the clear button.


    • clear_button_color_pressed

    Default

    Color( 1, 1, 1, 1 )

    Color used for the clear button when it’s pressed.


    Default

    Color( 0.94, 0.94, 0.94, 1 )

    Color of the LineEdit‘s visual cursor (caret).


    • font_color

    Default

    Color( 0.88, 0.88, 0.88, 1 )

    Default font color.


    • Color font_color_selected

    Default

    Color( 0, 0, 0, 1 )

    Font color for selected text (inside the selection rectangle).


    • font_color_uneditable

    Default

    Color( 0.88, 0.88, 0.88, 0.5 )

    Font color when editing is disabled.


    Default

    Color( 0.49, 0.49, 0.49, 1 )

    Color of the selection rectangle.


    • minimum_spaces

    Minimum horizontal space for the text (not counting the clear button and content margins). This value is measured in count of space characters (i.e. this amount of space characters can be displayed without scrolling).


    Font used for the text.


    • clear

    Texture for the clear button. See clear_button_enabled.


    • focus

    Background used when LineEdit has GUI focus.



    Background used when is in read-only mode ( is set to false).