LineEdit

Inherits: Control < CanvasItem < Node < Object

Control que proporciona la edición de string de una sola línea.

Descripción

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

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

Propiedades

Align

align

0

bool

caret_blink

false

float

caret_blink_speed

0.65

int

caret_position

0

bool

clear_button_enabled

false

bool

context_menu_enabled

true

bool

editable

true

bool

expand_to_text_length

false

FocusMode

focus_mode

2 (overrides Control)

int

max_length

0

CursorShape

mouse_default_cursor_shape

1 (overrides Control)

float

placeholder_alpha

0.6

String

placeholder_text

""

Texture

right_icon

bool

secret

false

String

secret_character

"*"

bool

selecting_enabled

true

bool

shortcut_keys_enabled

true

String

text

""

bool

virtual_keyboard_enabled

true

Métodos

void

append_at_cursor ( String text )

void

clear ( )

void

delete_char_at_cursor ( )

void

delete_text ( int from_column, int to_column )

void

deselect ( )

PopupMenu

get_menu ( ) const

int

get_scroll_offset ( ) const

void

menu_option ( int option )

void

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

void

select_all ( )

Propiedades del Theme

Color

clear_button_color

Color( 0.88, 0.88, 0.88, 1 )

Color

clear_button_color_pressed

Color( 1, 1, 1, 1 )

Color

cursor_color

Color( 0.94, 0.94, 0.94, 1 )

Color

font_color

Color( 0.88, 0.88, 0.88, 1 )

Color

font_color_selected

Color( 0, 0, 0, 1 )

Color

font_color_uneditable

Color( 0.88, 0.88, 0.88, 0.5 )

Color

selection_color

Color( 0.49, 0.49, 0.49, 1 )

int

minimum_spaces

12

Font

font

Texture

clear

StyleBox

focus

StyleBox

normal

StyleBox

read_only

Señales

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

Emitido cuando el texto cambia.


  • text_entered ( String new_text )

Emitido cuando el usuario presiona @GlobalScope.KEY_ENTER en la LineEdit.

Enumeraciones

enum Align:

  • ALIGN_LEFT = 0 --- Alinea el texto en el lado izquierdo de la LineEdit.

  • ALIGN_CENTER = 1 --- Centra el texto en el centro de la LineEdit.

  • ALIGN_RIGHT = 2 --- Alinea el texto en el lado derecho de la LineEdit.

  • ALIGN_FILL = 3 --- Estira los espacios en blanco para que se ajusten al ancho de la LineEdit.


enum MenuItems:

  • MENU_CUT = 0 --- Corta (copia y borra) el texto seleccionado.

  • MENU_COPY = 1 --- Copia el texto seleccionado.

  • MENU_PASTE = 2 --- Pega el texto del portapapeles sobre el texto seleccionado (o en la posición del cursor).

Los caracteres de escape no imprimibles se eliminan automáticamente del portapapeles del sistema operativo a través del String.strip_escapes.

  • MENU_CLEAR = 3 --- Borra todo el texto LineEdit.

  • MENU_SELECT_ALL = 4 --- Selecciona todo el texto LineEdit.

  • MENU_UNDO = 5 --- Deshace la acción anterior.

  • MENU_REDO = 6 --- Invierte la última acción de deshacer.

  • MENU_MAX = 7 --- Representa el tamaño del enum MenuItems.

Descripciones de Propiedades

Default

0

Setter

set_align(value)

Getter

get_align()

Alineación del texto como se define en el enum Align.


Default

false

Setter

cursor_set_blink_enabled(value)

Getter

cursor_get_blink_enabled()

Si true, el caret (cursor visual) parpadea.


Default

0.65

Setter

cursor_set_blink_speed(value)

Getter

cursor_get_blink_speed()

Duración (en segundos) del ciclo de parpadeo de un caret.


  • int caret_position

Default

0

Setter

set_cursor_position(value)

Getter

get_cursor_position()

La posición del cursor dentro de la LineEdit. Cuando se ajusta, el texto puede desplazarse para acomodarlo.


  • bool clear_button_enabled

Default

false

Setter

set_clear_button_enabled(value)

Getter

is_clear_button_enabled()

Si true, el LineEdit mostrará un botón de borrado si text no está vacío, que puede utilizarse para borrar el texto rápidamente.


  • bool context_menu_enabled

Default

true

Setter

set_context_menu_enabled(value)

Getter

is_context_menu_enabled()

Si true, el menú contextual aparecerá al hacer clic con el botón derecho del ratón.


Default

true

Setter

set_editable(value)

Getter

is_editable()

Si false, el texto existente no puede ser modificado y no se puede añadir un nuevo texto.


  • bool expand_to_text_length

Default

false

Setter

set_expand_to_text_length(value)

Getter

get_expand_to_text_length()

Si true, el ancho de LineEdit aumentará para permanecer más tiempo que el text.No se comprimirá si el text se acorta.


  • int max_length

Default

0

Setter

set_max_length(value)

Getter

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 max_length 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 text_change_rejected signal is emitted with the truncated substring as parameter.

Example:

text = "Hello world"
max_length = 5
# `text` becomes "Hello".
max_length = 10
text += " goodbye"
# `text` becomes "Hello good".
# `text_change_rejected` is emitted with "bye" as parameter.

  • float placeholder_alpha

Default

0.6

Setter

set_placeholder_alpha(value)

Getter

get_placeholder_alpha()

Opacidad del placeholder_text. De 0 a 1.


Default

""

Setter

set_placeholder(value)

Getter

get_placeholder()

El texto se muestra cuando la LineEdit está vacía. Es no el valor por defecto de LineEdit (véase el text).


Setter

set_right_icon(value)

Getter

get_right_icon()

Establece el icono que aparecerá en el extremo derecho de la LineEdit si no hay text, o siempre, si clear_button_enabled está establecido en false.


Default

false

Setter

set_secret(value)

Getter

is_secret()

Si true, cada carácter se sustituye por el carácter secreto (véase secret_character).


Default

"*"

Setter

set_secret_character(value)

Getter

get_secret_character()

El carácter que se usará para enmascarar la entrada secreta (por defecto es "*"). Sólo se puede utilizar un único carácter como el carácter secreto.


  • bool selecting_enabled

Default

true

Setter

set_selecting_enabled(value)

Getter

is_selecting_enabled()

Si false, es imposible seleccionar el texto usando el ratón o el teclado.


  • bool shortcut_keys_enabled

Default

true

Setter

set_shortcut_keys_enabled(value)

Getter

is_shortcut_keys_enabled()

Si false, el uso de atajos se desactivará.


Default

""

Setter

set_text(value)

Getter

get_text()

Valor de la strting de la LineEdit.

Nota: Cambiar el texto usando esta propiedad no emitirá la señal text_changed.


  • bool virtual_keyboard_enabled

Default

true

Setter

set_virtual_keyboard_enabled(value)

Getter

is_virtual_keyboard_enabled()

Si true, el teclado virtual nativo se muestra cuando se enfoca en plataformas que lo soportan.

Descripciones de Métodos

  • void append_at_cursor ( String text )

Añade text después del cursor. Si el valor resultante es mayor que max_length, no pasa nada.


  • void clear ( )

Borra el text de LineEdit.


  • void delete_char_at_cursor ( )

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


  • void delete_text ( int from_column, int to_column )

Elimina una sección del text que va de la posición from_column a to_column. Ambos parámetros deben estar dentro de la longitud del texto.


  • void deselect ( )

Borra la selección actual.


Returns the PopupMenu 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.


  • int get_scroll_offset ( ) const

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


  • void menu_option ( int option )

Ejecuta una acción determinada según se define en el enum MenuItems.


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

Selecciona los caracteres dentro de LineEdit entre from y to. Por defecto, from está al principio y to al final.

text = "Bienvenido"
select() # Seleccionará "Bienvenido".
select(4) # Seleccionará "venido".
select(2, 5) # Seleccionará "env".

  • void select_all ( )

Selecciona toda la String.

Theme Property Descriptions

  • Color clear_button_color

Default

Color( 0.88, 0.88, 0.88, 1 )

Color utilizado como tinte predeterminado para el botón de despejar.


  • Color clear_button_color_pressed

Default

Color( 1, 1, 1, 1 )

Color usado para el botón de borrado cuando se presiona.


Default

Color( 0.94, 0.94, 0.94, 1 )

Color del cursor visual (caret) de la LineEdit.


Default

Color( 0.88, 0.88, 0.88, 1 )

Color de fuente predeterminado.


  • Color font_color_selected

Default

Color( 0, 0, 0, 1 )

Color de fuente para el texto seleccionado (dentro del rectángulo de selección).


  • Color font_color_uneditable

Default

Color( 0.88, 0.88, 0.88, 0.5 )

El color de la fuente cuando la edición está desactivada.


Default

Color( 0.49, 0.49, 0.49, 1 )

Color del rectángulo de selección.


  • int minimum_spaces

Default

12

Espacio horizontal mínimo para el texto (sin contar el botón de borrar y los márgenes de contenido). Este valor se mide en el recuento de caracteres de espacio (es decir, esta cantidad de caracteres de espacio pueden ser mostrados sin desplazamiento).


Fuente usada para el texto.


La textura para el botón de despejar. Ver clear_button_enabled.


Fondo utilizado cuando LineEdit tiene el enfoque de la interfaz gráfica de usuario(GUI).


Fondo predeterminado para la LineEdit.


Fondo utilizado cuando LineEdit está en modo de sólo lectura (editable está configurado como false).