How do I set TabContainer custom_styles/panel StyleBox resource via gd script?

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

I have a project where I am attempting to click through tabs in my tab container node, and set the stylebox resource to something different for each corresponding tab.
I am able to callback from each tab click individually as needed, however, every source online i find, leads to me believe that in order to change
this property

in case image doesn’t load
by using onready var panel = get_stylebox("custom_styles/panel")
or onready var panel = get_stylebox("panel")
as the variable, and yet when I attempt to set the new value to a stylebox resource:

onready var red = load("res://source/art/red_styleboxflat.tres")
func _some_func():
    panel = red

It throws no errors, and no warnings, so I am left to believe that it is accessing something but not actually altering it as the code is set to do.

Is there some other way of changing the TabContainer custom stylebox “panel” property that has not been listed, or am I simply setting this value the wrong way?

:bust_in_silhouette: Reply From: njamster

What you’re looking for is:

var red = load("res://source/art/red_styleboxflat.tres")
set("custom_styles/panel", red)

What you did instead was:

  1. getting a copy of the stylebox
  2. saving it into a local variable panel
  3. then changing the value of that variable

That’s a valid operation, thus does not yield any errors or warning. However, it also doesn’t do what you want as it leaves the actual stylebox unchanged.

HOLY CRAP THANK YOU! I’ve been trying to scratch my noodle over this one for days now! This fixed everything!

Larck_Drakengold | 2020-03-21 18:53