OptionButton popupmenu background styling

Godot Version

4.2.2

Question

Hi,

I’m making use of an OptionButton in my game, which I am styling by changing the themes on a PopupMenu.

As seen in the image below, I have rounded the corners of the PopupMenu panels, however, there are still some remnants of a grey background (see where arrows are pointing).

I hope to remove this grey background and have tried to do so by changing the themes on many different nodes, to no avail.
image

If anyone knows the solution to this, it would be greatly appreciated, thanks

i think there’s an option to turn it round by making the window as transparent
the grey area is a window background, so you need to switch the transparent background option on to make it look round

1 Like

I’ve found a property transparent_bg under the PopupMenu’s Viewport node properties
image
It does what I’m looking for, however I can’t seem to access it as it’s created dynamically whenever the button is set up (I presume)

seen below is the remote scene tree during a play test
image

I’ve tried to get a reference to the PopupMenu node that is created but it doesn’t seem to want to let me, see below

func setBackgroundTransparent():
	# Check that the popup menu has children
	var children = button.get_children()
	print(children)
	print(children.size())
	
	if children.size() == 0:
		await get_tree().create_timer(0.25).timeout
		await setBackgroundTransparent()
	
	var popupWindowNode = children[0]
	if not popupWindowNode is PopupMenu:
		await get_tree().create_timer(0.25).timeout
		await setBackgroundTransparent()
	
	popupWindowNode.set("transparent_bg", true)

The two print statements in this code just continually print an empty array and a size of 0, so I’m not sure what’s going on

if you want to set the pop up menu to be transparent for the rounded rectangle, dont you just enabled this from here? no need from code

In the actual editor the only thing that is there is the OptionButton node
image

The PopupMenu is created by the engine whenever I run the game, so I can’t change its properties from the editor because it’s not there, hence why I’m trying to get a reference to it through code

sorry, i forgot popup menu and popup are two different things, so the popup menu has its own transparent because inheriting the viewport class

how do you reference for the button here? what is the node?

button is referring to the OptionButton node, which ends up being the parent of the PopupMenu that the engine creates

yes but how do you get the option button nodepath, is it from @export? @onready? or just get_node()?

ah my bad, it’s just an @onready annotation and there’s no issues with it being null - the reference is valid

i assume you call setBackgroundTransparent() at _ready()?
then you will want to wait for the popup to be ready first
something like putting

await get_tree().physics_frame

on the first line of this script _ready() function will do

that doesn’t change anything unfortunately

the function I sent earlier (setBackgroundTransparency()) is being called recursively every .25 seconds so it should wait until there is a child to perform the setting of the transparent background,

even after letting it run for a few minutes the OptionButton apparently still has no children, when in the remote scene tree it looks like it should

a simple test:


image

show your code how you reference the option button node

@onready var button: OptionButton = $Control/MarginContainer/OptionButton

I can assure you the reference is valid

Did you add the PopupMenu node to the scene tree yourself? the one I’m trying to reference only exists on the remote tree – i.e. while the game is running

then you can just assign the newly instantiated and added child OptionButton to button, dont pre-add it because it havent existed, hence none

I’ve figured it out - had to pass the include_internal parameter through the get_children() call for it to recognize the PopupMenu inside the OptionButton

var children = button.get_children(true)

thanks for taking the time to offer your help though, I truly appreciate it, thanks

did you added child with this internal parameter altered?

I didn’t change anything about the scene tree - no new children added or anything

The PopupMenu is created by the engine as an internal child of the OptionButton (I think… whatever that means), so I just had to tell my code to look for those internal children when trying to get the children of the OptionButton

you are right, also i thought of that just now
image

well, i never really used the option button because lots of viewport consume lots of fps

1 Like