diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml
index ac56d5c433e..6553e86421d 100644
--- a/doc/classes/TreeItem.xml
+++ b/doc/classes/TreeItem.xml
@@ -203,6 +203,13 @@
Returns custom font size used to draw text in the column [param column].
+
+
+
+
+ Returns the given column's custom [StyleBox] used to draw the background.
+
+
@@ -614,6 +621,7 @@
Sets the given column's custom background color and whether to just use it as an outline.
+ [b]Note:[/b] If a custom [StyleBox] is set, the background color will be drawn behind it.
@@ -659,6 +667,15 @@
Sets custom font size used to draw text in the given [param column].
+
+
+
+
+
+ Sets the given column's custom [StyleBox] used to draw the background.
+ [b]Note:[/b] If a custom background color is set, the [StyleBox] will be drawn in front of it.
+
+
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 2173a63cd95..84c6911f5f8 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -878,6 +878,17 @@ int TreeItem::get_custom_minimum_height() const {
return custom_min_height;
}
+void TreeItem::set_custom_stylebox(int p_column, const Ref &p_stylebox) {
+ ERR_FAIL_INDEX(p_column, cells.size());
+ cells.write[p_column].custom_stylebox = p_stylebox;
+ _changed_notify(p_column);
+}
+
+Ref TreeItem::get_custom_stylebox(int p_column) const {
+ ERR_FAIL_INDEX_V(p_column, cells.size(), Ref());
+ return cells[p_column].custom_stylebox;
+}
+
TreeItem *TreeItem::create_child(int p_index) {
TreeItem *ti = memnew(TreeItem(tree));
if (tree) {
@@ -1843,6 +1854,9 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_custom_draw_callback", "column", "callback"), &TreeItem::set_custom_draw_callback);
ClassDB::bind_method(D_METHOD("get_custom_draw_callback", "column"), &TreeItem::get_custom_draw_callback);
+ ClassDB::bind_method(D_METHOD("set_custom_stylebox", "column", "stylebox"), &TreeItem::set_custom_stylebox);
+ ClassDB::bind_method(D_METHOD("get_custom_stylebox", "column"), &TreeItem::get_custom_stylebox);
+
ClassDB::bind_method(D_METHOD("set_collapsed", "enable"), &TreeItem::set_collapsed);
ClassDB::bind_method(D_METHOD("is_collapsed"), &TreeItem::is_collapsed);
@@ -2436,6 +2450,16 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
}
+ if (p_item->cells[i].custom_stylebox.is_valid()) {
+ Rect2 r = cell_rect;
+ if (i == 0) {
+ r.position.x = p_draw_ofs.x;
+ r.size.x = item_width + ofs;
+ }
+ r = convert_rtl_rect(r);
+ draw_style_box(p_item->cells[i].custom_stylebox, r);
+ }
+
if (drop_mode_flags && drop_mode_over) {
Rect2 r = convert_rtl_rect(cell_rect);
if (drop_mode_over == p_item) {
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 4df37298c01..2d085677236 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -98,6 +98,7 @@ private:
bool custom_button = false;
bool expand_right = false;
Color icon_color = Color(1, 1, 1);
+ Ref custom_stylebox;
Size2i cached_minimum_size;
bool cached_minimum_size_dirty = true;
@@ -359,6 +360,9 @@ public:
void set_custom_minimum_height(int p_height);
int get_custom_minimum_height() const;
+ void set_custom_stylebox(int p_column, const Ref &p_stylebox);
+ Ref get_custom_stylebox(int p_column) const;
+
void set_selectable(int p_column, bool p_selectable);
bool is_selectable(int p_column) const;