diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml
index 2bd76e619..9b622d84c 100644
--- a/doc/classes/Tree.xml
+++ b/doc/classes/Tree.xml
@@ -202,6 +202,14 @@
Sets the title of a column.
+
+
+
+
+
+ Selects the specified [TreeItem] and column.
+
+
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 24fc67617..0df5086d8 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -3161,6 +3161,12 @@ TreeItem *Tree::get_selected() const {
return selected_item;
}
+void Tree::set_selected(TreeItem *p_item, int p_column) {
+ ERR_FAIL_INDEX(p_column, columns.size());
+ ERR_FAIL_COND(!p_item);
+ select_single_item(p_item, get_root(), p_column);
+}
+
int Tree::get_selected_column() const {
return selected_col;
}
@@ -3836,6 +3842,7 @@ void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_root_hidden"), &Tree::is_root_hidden);
ClassDB::bind_method(D_METHOD("get_next_selected", "from"), &Tree::_get_next_selected);
ClassDB::bind_method(D_METHOD("get_selected"), &Tree::get_selected);
+ ClassDB::bind_method(D_METHOD("set_selected", "item", "column"), &Tree::_set_selected);
ClassDB::bind_method(D_METHOD("get_selected_column"), &Tree::get_selected_column);
ClassDB::bind_method(D_METHOD("get_pressed_button"), &Tree::get_pressed_button);
ClassDB::bind_method(D_METHOD("set_select_mode", "mode"), &Tree::set_select_mode);
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index f4f7171ed..e11ef12f1 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -528,6 +528,10 @@ protected:
scroll_to_item(Object::cast_to(p_item));
}
+ void _set_selected(Object *p_item, int p_column) {
+ set_selected(Object::cast_to(p_item), p_column);
+ }
+
public:
virtual String get_tooltip(const Point2 &p_pos) const;
@@ -550,6 +554,7 @@ public:
bool is_root_hidden() const;
TreeItem *get_next_selected(TreeItem *p_item);
TreeItem *get_selected() const;
+ void set_selected(TreeItem *p_item, int p_column = 0);
int get_selected_column() const;
int get_pressed_button() const;
void set_select_mode(SelectMode p_mode);