Multiple choice dropdown?

Godot Version

4.3

Question

How can i make a dropdown menu that multiple choices can be selected? I tried optionbutton but it seems not fit.

The option button is single select only. I think you will have to make one yourself.

Here is a trivial implementation. Create a control node, add a script and add this to see it working. You will have to adjust it to your cause for how you implement it for whatever behaviour you want it to have, ie how to close it (I imagine another button or altering the text on original button if it is open or closed etc)

In a control node script:

extends Control

var dropdown_button: Button
var item_list: VBoxContainer
var items = ["Apple", "Banana", "Cherry", "Date"]

func _ready():
	dropdown_button = Button.new()
	dropdown_button.text = "Select Items"
	dropdown_button.connect("pressed", _on_dropdown_button_pressed)
	add_child(dropdown_button)

	item_list = VBoxContainer.new()
	item_list.visible = false
	# Move list away from original button
	item_list.position.y += 50
	add_child(item_list)

	for item in items:
		var checkbox = CheckBox.new()
		checkbox.text = item
		item_list.add_child(checkbox)

func _on_dropdown_button_pressed():
	item_list.visible = !item_list.visible


func get_selected_items():
	var selected = []
	for child in item_list.get_children():
		if child is CheckBox and child.pressed:
			selected.append(child.text)
	return selected

Hope that helps.

Or use the ItemList with select mode set to multi.

Just tested this and it is quite nice (never used it before though but it looks great). Again you can make it appear and disappear on a btn pressed.

You have to press CTRL to multi select.

PS It still amazes me the amount of Nodes that Godot has prebuilt!

image

Thanks a lot!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.