0 votes

I want to be able to change the background color of a StyleBoxFlat I put on a specific panel, but any attempt to get that StyleBox just returns a StyleBoxTexture. I tried making a theme for it and changing the StyleBox for the panel there but still the same issue.

The only thing that works is having an export var that I can then use to edit the StyleBox, but I don't want to have a static variable for each panel I want to change the background color of when it's so much easier to just pass the panel to a function.

Godot version 3.3.3
in Engine by (12 points)

1 Answer

0 votes

This is straight outta docs:

void addstyleboxoverride(name: String, stylebox: StyleBox)

Overrides the StyleBox with given name in the theme resource the control uses. If stylebox is empty or invalid, the override is cleared and the StyleBox from assigned Theme is used.

Example of modifying a property in a StyleBox by duplicating it:

# The snippet below assumes the child node MyButton has a StyleBoxFlat assigned.
# Resources are shared across instances, so we need to duplicate it
# to avoid modifying the appearance of all other buttons.
var new_stylebox_normal = $MyButton.get_stylebox("normal").duplicate()
new_stylebox_normal.border_width_top = 3
new_stylebox_normal.border_color = Color(0, 1, 0.5)
$MyButton.add_stylebox_override("normal", new_stylebox_normal)

# Remove the stylebox override:
$MyButton.add_stylebox_override("normal", null)

If you don't have theme or stylebox assigned just create new one :

var box = StyleBoxFlat.new();
by (120 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.