@@ -147,9 +147,7 @@ void TabContainer::_notification(int p_what) {
147147 if (get_tab_count () > 0 ) {
148148 _refresh_tab_names ();
149149 }
150- } break ;
151150
152- case NOTIFICATION_POST_ENTER_TREE: {
153151 if (setup_current_tab >= -1 ) {
154152 set_current_tab (setup_current_tab);
155153 setup_current_tab = -2 ;
@@ -191,6 +189,25 @@ void TabContainer::_notification(int p_what) {
191189 }
192190 } break ;
193191
192+ case NOTIFICATION_VISIBILITY_CHANGED: {
193+ if (!is_visible () || setup_current_tab > -2 ) {
194+ return ;
195+ }
196+
197+ updating_visibility = true ;
198+
199+ // As the visibility change notification will be triggered for all children soon after,
200+ // beat it to the punch and make sure that the correct node is the only one visible first.
201+ // Otherwise, it can prevent a tab change done right before this container was made visible.
202+ Vector<Control *> controls = _get_tab_controls ();
203+ int current = get_current_tab ();
204+ for (int i = 0 ; i < controls.size (); i++) {
205+ controls[i]->set_visible (i == current);
206+ }
207+
208+ updating_visibility = false ;
209+ } break ;
210+
194211 case NOTIFICATION_TRANSLATION_CHANGED:
195212 case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
196213 case NOTIFICATION_THEME_CHANGED: {
@@ -611,6 +628,7 @@ void TabContainer::set_current_tab(int p_current) {
611628 setup_current_tab = p_current;
612629 return ;
613630 }
631+
614632 tab_bar->set_current_tab (p_current);
615633}
616634
0 commit comments