how to focus another lineedit without clicking tab key

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By nahcode

i need to change focus to another lineedit, lineedit has property to set which is next lineedit to focus on, but as far as i know it is using tab key to trigger the next focus, how to change focus to the next lineedit, after user input 5 letter in previous lineedit,

i already using grab_focus() function, but i just want to know, is there another way using next focus property and trigger it using some condition from script,

nahcode | 2022-03-11 07:25

:bust_in_silhouette: Reply From: codelyok13

There should be something like a text_changed signal for LineEdit.


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 )

Emitted when the text changes.

text_entered ( String new_text )

Emitted when the user presses @GlobalScope.KEY_ENTER on the LineEdit.

LineEdit Godot

You should have that signal run anytime a key is pressed and when the length of the text has reach 5 use the grab_focus code to move to the next line edit.

func on_LineEdit(text_changed):
        if len(text) == 5: #Assumption: Code is in current LineEdit
               #Called grab_focus() code for LineEdit2.

oo okay, thank you this gives me another way of thinking, using this way i need to define which lineedit i want to go next, like on every lineedit right?,

NodePath focus_next [default: NodePath(“”)]
set_focus_next(value) setter
get_focus_next() getter

Tells Godot which node it should give keyboard focus to if the user
presses Tab on a keyboard by default. You can change the key by
editing the ui_focus_next input action.

If this property is not set, Godot will select a “best guess” based on
surrounding nodes in the scene tree.

this from focus_next doc

when i click tab key, godot “guessing” which is next lineedit, and i dont need to define that like $lineedit.grab_focus(), godot like “knows” which is the next lineedit

can i just go to “next” lineedit after certain condition is true, without defining it before because it is just next to it? is that possible?

is this understandable? im sorry my poor english, but thank you

nahcode | 2022-03-11 22:04

This looks like what you are looking for but instead you want to emit ui_tab or ui_next.

Godot InputEvents

codelyok13 | 2022-03-12 03:34