diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml
index 9510d237da93..3b50c9ea95c9 100644
--- a/doc/classes/Tree.xml
+++ b/doc/classes/Tree.xml
@@ -341,6 +341,9 @@
If [code]true[/code], allows navigating the [Tree] with letter keys through incremental search.
+
+ If [code]true[/code], tree items with no tooltip assigned display their text as their tooltip.
+
If [code]true[/code], column titles are visible.
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 6159e26efa9e..24106c362c67 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -5783,7 +5783,7 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
if (it) {
const String item_tooltip = it->get_tooltip_text(col);
- if (item_tooltip.is_empty()) {
+ if (enable_auto_tooltip && item_tooltip.is_empty()) {
return it->get_text(col);
}
return item_tooltip;
@@ -5865,6 +5865,14 @@ bool Tree::get_allow_search() const {
return allow_search;
}
+void Tree::set_auto_tooltip(bool p_enable) {
+ enable_auto_tooltip = p_enable;
+}
+
+bool Tree::is_auto_tooltip_enabled() const {
+ return enable_auto_tooltip;
+}
+
void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear"), &Tree::clear);
ClassDB::bind_method(D_METHOD("create_item", "parent", "index"), &Tree::create_item, DEFVAL(Variant()), DEFVAL(-1));
@@ -5948,6 +5956,9 @@ void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_allow_search", "allow"), &Tree::set_allow_search);
ClassDB::bind_method(D_METHOD("get_allow_search"), &Tree::get_allow_search);
+ ClassDB::bind_method(D_METHOD("set_auto_tooltip", "enable"), &Tree::set_auto_tooltip);
+ ClassDB::bind_method(D_METHOD("is_auto_tooltip_enabled"), &Tree::is_auto_tooltip_enabled);
+
ADD_PROPERTY(PropertyInfo(Variant::INT, "columns"), "set_columns", "get_columns");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "column_titles_visible"), "set_column_titles_visible", "are_column_titles_visible");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_reselect"), "set_allow_reselect", "get_allow_reselect");
@@ -5960,6 +5971,7 @@ void Tree::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Row,Multi"), "set_select_mode", "get_select_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_horizontal_enabled"), "set_h_scroll_enabled", "is_h_scroll_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_vertical_enabled"), "set_v_scroll_enabled", "is_v_scroll_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_tooltip"), "set_auto_tooltip", "is_auto_tooltip_enabled");
ADD_SIGNAL(MethodInfo("item_selected"));
ADD_SIGNAL(MethodInfo("cell_selected"));
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index b417b7ee316b..2bae1906f3ce 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -699,6 +699,8 @@ class Tree : public Control {
bool enable_recursive_folding = true;
+ bool enable_auto_tooltip = true;
+
void _determine_hovered_item();
int _count_selected_items(TreeItem *p_from) const;
@@ -830,6 +832,9 @@ class Tree : public Control {
void set_allow_search(bool p_allow);
bool get_allow_search() const;
+ void set_auto_tooltip(bool p_enable);
+ bool is_auto_tooltip_enabled() const;
+
Size2 get_minimum_size() const override;
Tree();