I have a problem with tab container

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

Tab container is almost perfect but there is a flaw. You can’t customize the name of the tab in real-time.
Does anyone know how to customize the tab’s name real-time?

What do you mean? The name of the tab changes to match the name of the child node.

exuin | 2021-04-22 15:02

:bust_in_silhouette: Reply From: clemens.tolboom

Someting like this:

onready var tabs:TabContainer = $TabContainer

func _ready():
	tabs.set_tab_title(0, "Tab 1")
	tabs.set_tab_title(1, "Tab 2")
:bust_in_silhouette: Reply From: Bubu

Here’s my solution from a previous question:

You can use tab_selected(int tab) signal from each tab and trigger a one shot timer whenever a click event is received. If a click occurred while the timer is active (double click), popup a dialog that contains a LineEdit, confirmation button and a cancel button. when the user confirms, use set_tab_title() to edit the title.

Make sure you pass up the tab number from tab_selected(int tab) so that you know which tab to change its title.

:bust_in_silhouette: Reply From: FourthMouse

I needed to change the tab names to their translated strings. The string displayed to the user in the ui is just the name of the node.

As Clemens mentioned, you can change the tab title if you know the index of the tab (this sets the name of the node) but you can also attach a script directly to the tab which is how I solved my translation problem.

The script below saves the initial name of the tab in the onready var translationName, and then sets it to the translated string on ready and also when the ReTranslate signal is emitted.

extends Tabs

onready var translationName:String = self.name

func _ready() -> void:
	SettingsLanguage.connect("ReTranslate", self, "retranslate")
	retranslate()

func retranslate() -> void:
	self.name = tr(translationName)

relevant documentation:

https://docs.godotengine.org/en/stable/classes/class_tabs.html