0 votes

I set the button's color by themeoverrides.
And, I tried to change bg color of button by coding;
Set("custom_styles/normal/bg_color", Color.Color8(255,0,0,255));
However, runnning that code, the bg color of button returns to initial one.
Please tell me how can I change bg color

Godot version 3.4.4
in Engine by (12 points)

1 Answer

+1 vote

Button inherits from Control node. When I wanted to change font in RichTextLabel (originates from Control node too) I used:

var fontForExplanation = rtlExample.GetFont("normal_font","");
(fontForExplanation as DynamicFont).Size = 24; 

There may be hints here:

Theme resources change the Control's appearance. If you change the Theme on a Control node, it affects all of its children. To override some of the theme's parameters, call one of the add*override methods, like AddFontOverride(String, Font). You can override the theme with the inspector.
Note: Theme items are not Object properties. This means you can't access their values using Get(String) and Set(String, Object). Instead, use GetColor(String, String), GetConstant(String, String), GetFont(String, String), GetIcon(String, String), GetStylebox(String, String), and the add*override methods provided by this class.

And here (there are examples in this address, which may help)

GetColor(String, String)
Returns a Color from the first matching Theme in the tree if that Theme has a color item with the specified name and themetype. If themetype is omitted the class name of the current control is used as the type. If the type is a class name its parent classes are also checked, in order of inheritance.
For the current control its local overrides are considered first (see AddColorOverride(String, Color)), then its assigned Theme. After the current control, each parent control and its assigned Theme are considered; controls without a Theme assigned are skipped. If no matching Theme is found in the tree, a custom project Theme (see ) and the default Theme are used.

by (25 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 Frequently asked questions and 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 [email protected] with your username.