diff --git a/doc/classes/ButtonGroup.xml b/doc/classes/ButtonGroup.xml
index 3e153ea1aaf..ebc902bea7d 100644
--- a/doc/classes/ButtonGroup.xml
+++ b/doc/classes/ButtonGroup.xml
@@ -24,6 +24,9 @@
+
+ If [code]true[/code], it is possible to unpress all buttons in this [ButtonGroup].
+
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index c26a00221a3..e5b77654cf0 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -40,7 +40,7 @@ void BaseButton::_unpress_group() {
return;
}
- if (toggle_mode) {
+ if (toggle_mode && !button_group->is_allow_unpress()) {
status.pressed = true;
}
@@ -537,9 +537,20 @@ BaseButton *ButtonGroup::get_pressed_button() {
return nullptr;
}
+void ButtonGroup::set_allow_unpress(bool p_enabled) {
+ allow_unpress = p_enabled;
+}
+bool ButtonGroup::is_allow_unpress() {
+ return allow_unpress;
+}
+
void ButtonGroup::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_pressed_button"), &ButtonGroup::get_pressed_button);
ClassDB::bind_method(D_METHOD("get_buttons"), &ButtonGroup::_get_buttons);
+ ClassDB::bind_method(D_METHOD("set_allow_unpress", "enabled"), &ButtonGroup::set_allow_unpress);
+ ClassDB::bind_method(D_METHOD("is_allow_unpress"), &ButtonGroup::is_allow_unpress);
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_unpress"), "set_allow_unpress", "is_allow_unpress");
ADD_SIGNAL(MethodInfo("pressed", PropertyInfo(Variant::OBJECT, "button", PROPERTY_HINT_RESOURCE_TYPE, "BaseButton")));
}
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index 962a16c4539..a8d5cee44ca 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -152,6 +152,7 @@ class ButtonGroup : public Resource {
GDCLASS(ButtonGroup, Resource);
friend class BaseButton;
HashSet buttons;
+ bool allow_unpress = false;
protected:
static void _bind_methods();
@@ -160,6 +161,8 @@ public:
BaseButton *get_pressed_button();
void get_buttons(List *r_buttons);
TypedArray _get_buttons();
+ void set_allow_unpress(bool p_enabled);
+ bool is_allow_unpress();
ButtonGroup();
};