Stupid question but I don’t manage to find the solution : I can’t get the focus switch to work. I have a few TextEdits and when one of them has the focus and I hit Tab (or shift-Tab) nothing happens. I’ve tried to put proper NodePaths in focus_next and focus_previous, to no avail.
I’m stuck.
From my testing, the TextEdit will absorb that input and insert a tab at the cursor(s).
You could add a script to the TextEdit to manually change the focused control when the user presses Tab, like below:
extends TextEdit
func _gui_input(event: InputEvent) -> void:
var event_key := event as InputEventKey
if event_key and event_key.pressed and event_key.keycode == KEY_TAB:
if event_key.shift_pressed:
find_prev_valid_focus().grab_focus.call_deferred()
else:
find_next_valid_focus().grab_focus.call_deferred()
Note that this example will still type the tab before focusing another control.
I realize I made a mistake, it’s not a TextEdit but a LineEdit. I don’t know if it changes anything. But I get the Tabs drawn inside TextEdits but not inside LineEdits.
I got it, and it was a stupid mistake from my side. I was wrongly linking my Nodes, mixing focus_next and focus_previous.
But I also needed your code, so thank you, it’s fixed!
It’s a bit weird that by default Line/TextEdits absorb Tab without scrolling through Controls. It’d have been neat to just check a box to get this behavior without adding code.