Skip to content

TreeItem

Inherits: Object

An internal control for a single item inside Tree.

A single item of a Tree control. It can contain other TreeItems as children, which allows it to create a hierarchy. It can also contain text and buttons. TreeItem is not a Entity, it is internal to the Tree.

To create a TreeItem, use Tree.create_item() or create_child(). To remove a TreeItem, use Object.free().

Note: The ID values used for buttons are 32-bit, unlike int which is always 64-bit. They go from -2147483648 to 2147483647.

Type Name Default
bool collapsed
int custom_minimum_height
bool disable_folding
bool visible
Returns Method
void add_button(column: int, button: Texture2D, id: int = -1, disabled: bool = false, tooltip_text: String = "", description: String = "")
void add_child(child: TreeItem)
void call_recursive(method: StringName, …) vararg
void clear_buttons()
void clear_custom_bg_color(column: int)
void clear_custom_color(column: int)
TreeItem create_child(index: int = -1)
void deselect(column: int)
void erase_button(column: int, button_index: int)
Entity.AutoTranslateMode get_auto_translate_mode(column: int) const
TextSystem.AutowrapMode get_autowrap_mode(column: int) const
BitField[TextSystem.LineBreakFlag] get_autowrap_trim_flags(column: int) const
Texture2D get_button(column: int, button_index: int) const
int get_button_by_id(column: int, id: int) const
Color get_button_color(column: int, id: int) const
int get_button_count(column: int) const
int get_button_id(column: int, button_index: int) const
String get_button_tooltip_text(column: int, button_index: int) const
TreeCellMode get_cell_mode(column: int) const
TreeItem get_child(index: int)
int get_child_count()
Array[TreeItem] get_children()
Color get_custom_bg_color(column: int) const
Color get_custom_color(column: int) const
Callable get_custom_draw_callback(column: int) const
Font get_custom_font(column: int) const
int get_custom_font_size(column: int) const
StyleBox get_custom_stylebox(column: int) const
String get_description(column: int) const
bool get_expand_right(column: int) const
TreeItem get_first_child() const
Texture2D get_icon(column: int) const
int get_icon_max_width(column: int) const
Color get_icon_modulate(column: int) const
Texture2D get_icon_overlay(column: int) const
Rect2 get_icon_region(column: int) const
int get_index()
String get_language(column: int) const
Variant get_metadata(column: int) const
TreeItem get_next() const
TreeItem get_next_in_tree(wrap: bool = false)
TreeItem get_next_visible(wrap: bool = false)
TreeItem get_parent() const
TreeItem get_prev()
TreeItem get_prev_in_tree(wrap: bool = false)
TreeItem get_prev_visible(wrap: bool = false)
float get_range(column: int) const
Dictionary get_range_config(column: int)
TextSystem.StructuredTextParser get_structured_text_bidi_override(column: int) const
Array get_structured_text_bidi_override_options(column: int) const
String get_suffix(column: int) const
String get_text(column: int) const
HorizontalAlignment get_text_alignment(column: int) const
Control.TextDirection get_text_direction(column: int) const
TextSystem.OverrunBehavior get_text_overrun_behavior(column: int) const
String get_tooltip_text(column: int) const
Tree get_tree() const
bool is_accepting_children() const
bool is_any_collapsed(only_visible: bool = false)
bool is_button_disabled(column: int, button_index: int) const
bool is_checked(column: int) const
bool is_custom_set_as_button(column: int) const
bool is_edit_multiline(column: int) const
bool is_editable(column: int)
bool is_indeterminate(column: int) const
bool is_selectable(column: int) const
bool is_selected(column: int)
bool is_visible_in_tree() const
void move_after(item: TreeItem)
void move_before(item: TreeItem)
void propagate_check(column: int, emit_signal: bool = true)
void remove_child(child: TreeItem)
void select(column: int, set_as_cursor: bool = true)
void set_accept_children(allowed: bool)
void set_auto_translate_mode(column: int, mode: Entity.AutoTranslateMode)
void set_autowrap_mode(column: int, autowrap_mode: TextSystem.AutowrapMode)
void set_autowrap_trim_flags(column: int, flags: BitField[TextSystem.LineBreakFlag])
void set_button(column: int, button_index: int, button: Texture2D)
void set_button_color(column: int, button_index: int, color: Color)
void set_button_description(column: int, button_index: int, description: String)
void set_button_disabled(column: int, button_index: int, disabled: bool)
void set_button_tooltip_text(column: int, button_index: int, tooltip: String)
void set_cell_mode(column: int, mode: TreeCellMode)
void set_checked(column: int, checked: bool)
void set_collapsed_recursive(enable: bool)
void set_custom_as_button(column: int, enable: bool)
void set_custom_bg_color(column: int, color: Color, just_outline: bool = false)
void set_custom_color(column: int, color: Color)
void set_custom_draw_callback(column: int, callback: Callable)
void set_custom_font(column: int, font: Font)
void set_custom_font_size(column: int, font_size: int)
void set_custom_stylebox(column: int, stylebox: StyleBox)
void set_description(column: int, description: String)
void set_edit_multiline(column: int, multiline: bool)
void set_editable(column: int, enabled: bool)
void set_expand_right(column: int, enable: bool)
void set_icon(column: int, texture: Texture2D)
void set_icon_max_width(column: int, width: int)
void set_icon_modulate(column: int, modulate: Color)
void set_icon_overlay(column: int, texture: Texture2D)
void set_icon_region(column: int, region: Rect2)
void set_indeterminate(column: int, indeterminate: bool)
void set_language(column: int, language: String)
void set_metadata(column: int, meta: Variant)
void set_range(column: int, value: float)
void set_range_config(column: int, min: float, max: float, step: float, expr: bool = false)
void set_selectable(column: int, selectable: bool)
void set_structured_text_bidi_override(column: int, parser: TextSystem.StructuredTextParser)
void set_structured_text_bidi_override_options(column: int, args: Array)
void set_suffix(column: int, text: String)
void set_text(column: int, text: String)
void set_text_alignment(column: int, text_alignment: HorizontalAlignment)
void set_text_direction(column: int, direction: Control.TextDirection)
void set_text_overrun_behavior(column: int, overrun_behavior: TextSystem.OverrunBehavior)
void set_tooltip_text(column: int, tooltip: String)
void uncollapse_tree()

TreeCellMode

enum TreeCellMode

CELL_MODE_STRING = 0

Cell shows a string label, optionally with an icon. When editable, the text can be edited using a LineEdit, or a TextEdit popup if set_edit_multiline() is used.

CELL_MODE_CHECK = 1

Cell shows a checkbox, optionally with text and an icon. The checkbox can be pressed, released, or indeterminate (via set_indeterminate()). The checkbox can’t be clicked unless the cell is editable.

CELL_MODE_RANGE = 2

Cell shows a numeric range. When editable, it can be edited using a range slider. Use set_range() to set the value and set_range_config() to configure the range.

This cell can also be used in a text dropdown mode when you assign a text with set_text(). Separate options with a comma, e.g. "Option1,Option2,Option3".

CELL_MODE_ICON = 3

Cell shows an icon. It can’t be edited nor display text. The icon is always centered within the cell.

CELL_MODE_CUSTOM = 4

Cell shows as a clickable button. It will display an arrow similar to OptionButton, but doesn’t feature a dropdown (for that you can use CELL_MODE_RANGE). Clicking the button emits the Tree.item_edited signal. The button is flat by default, you can use set_custom_as_button() to display it with a StyleBox.

This mode also supports custom drawing using set_custom_draw_callback().

collapsed

bool collapsed

If true, the TreeItem is collapsed.

custom_minimum_height

int custom_minimum_height

The custom minimum height.

disable_folding

bool disable_folding

If true, folding is disabled for this TreeItem.

visible

bool visible

If true, the TreeItem is visible (default).

Note that if a TreeItem is set to not be visible, none of its children will be visible either.

add_button

void add_button(column: int, button: Texture2D, id: int = -1, disabled: bool = false, tooltip_text: String = "", description: String = "")

Adds a button with Texture2D button to the end of the cell at column column. The id is used to identify the button in the according Tree.button_clicked signal and can be different from the buttons index. If not specified, the next available index is used, which may be retrieved by calling get_button_count() immediately before this method. Optionally, the button can be disabled and have a tooltip_text. description is used as the button description for assistive apps.

add_child

void add_child(child: TreeItem)

Adds a previously unparented TreeItem as a direct child of this one. The child item must not be a part of any Tree or parented to any TreeItem. See also remove_child().

call_recursive

void call_recursive(method: StringName, …) vararg

Calls the method on the actual TreeItem and its children recursively. Pass parameters as a comma separated list.

clear_buttons

void clear_buttons()

Removes all buttons from all columns of this item.

clear_custom_bg_color

void clear_custom_bg_color(column: int)

Resets the background color for the given column to default.

clear_custom_color

void clear_custom_color(column: int)

Resets the color for the given column to default.

create_child

TreeItem create_child(index: int = -1)

Creates an item and adds it as a child.

The new item will be inserted as position index (the default value -1 means the last position), or it will be the last child if index is higher than the child count.

deselect

void deselect(column: int)

Deselects the given column.

erase_button

void erase_button(column: int, button_index: int)

Removes the button at index button_index in column column.

get_auto_translate_mode

Entity.AutoTranslateMode get_auto_translate_mode(column: int) const

Returns the column’s auto translate mode.

get_autowrap_mode

TextSystem.AutowrapMode get_autowrap_mode(column: int) const

Returns the text autowrap mode in the given column. By default it is TextSystem.AUTOWRAP_OFF.

get_autowrap_trim_flags

BitField[TextSystem.LineBreakFlag] get_autowrap_trim_flags(column: int) const

Returns the autowrap trim flags for the given column. By default, both TextSystem.BREAK_TRIM_START_EDGE_SPACES and TextSystem.BREAK_TRIM_END_EDGE_SPACES are enabled.

get_button

Texture2D get_button(column: int, button_index: int) const

Returns the Texture2D of the button at index button_index in column column.

get_button_by_id

int get_button_by_id(column: int, id: int) const

Returns the button index if there is a button with ID id in column column, otherwise returns -1.

get_button_color

Color get_button_color(column: int, id: int) const

Returns the color of the button with ID id in column column. If the specified button does not exist, returns Color.BLACK.

get_button_count

int get_button_count(column: int) const

Returns the number of buttons in column column.

get_button_id

int get_button_id(column: int, button_index: int) const

Returns the ID for the button at index button_index in column column.

get_button_tooltip_text

String get_button_tooltip_text(column: int, button_index: int) const

Returns the tooltip text for the button at index button_index in column column.

get_cell_mode

TreeCellMode get_cell_mode(column: int) const

Returns the column’s cell mode.

get_child

TreeItem get_child(index: int)

Returns a child item by its index (see get_child_count()). This method is often used for iterating all children of an item.

Negative indices access the children from the last one.

get_child_count

int get_child_count()

Returns the number of child items.

get_children

Array[TreeItem] get_children()

Returns an array of references to the item’s children.

get_custom_bg_color

Color get_custom_bg_color(column: int) const

Returns the custom background color of column column.

get_custom_color

Color get_custom_color(column: int) const

Returns the custom color of column column.

get_custom_draw_callback

Callable get_custom_draw_callback(column: int) const

Returns the custom callback of column column.

get_custom_font

Font get_custom_font(column: int) const

Returns custom font used to draw text in the column column.

get_custom_font_size

int get_custom_font_size(column: int) const

Returns custom font size used to draw text in the column column.

get_custom_stylebox

StyleBox get_custom_stylebox(column: int) const

Returns the given column’s custom StyleBox used to draw the background.

get_description

String get_description(column: int) const

Returns the given column’s description for assistive apps.

get_expand_right

bool get_expand_right(column: int) const

Returns true if expand_right is set.

get_first_child

TreeItem get_first_child() const

Returns the TreeItem’s first child.

get_icon

Texture2D get_icon(column: int) const

Returns the given column’s icon Texture2D. Error if no icon is set.

get_icon_max_width

int get_icon_max_width(column: int) const

Returns the maximum allowed width of the icon in the given column.

get_icon_modulate

Color get_icon_modulate(column: int) const

Returns the Color modulating the column’s icon.

get_icon_overlay

Texture2D get_icon_overlay(column: int) const

Returns the given column’s icon overlay Texture2D.

get_icon_region

Rect2 get_icon_region(column: int) const

Returns the icon Texture2D region as Rect2.

get_index

int get_index()

Returns the node’s order in the tree. For example, if called on the first child item the position is 0.

get_language

String get_language(column: int) const

Returns item’s text language code.

get_metadata

Variant get_metadata(column: int) const

Returns the metadata value that was set for the given column using set_metadata().

get_next

TreeItem get_next() const

Returns the next sibling TreeItem in the tree or a null object if there is none.

get_next_in_tree

TreeItem get_next_in_tree(wrap: bool = false)

Returns the next TreeItem in the tree (in the context of a depth-first search) or a null object if there is none.

If wrap is enabled, the method will wrap around to the first element in the tree when called on the last element, otherwise it returns null.

get_next_visible

TreeItem get_next_visible(wrap: bool = false)

Returns the next visible TreeItem in the tree (in the context of a depth-first search) or a null object if there is none.

If wrap is enabled, the method will wrap around to the first visible element in the tree when called on the last visible element, otherwise it returns null.

get_parent

TreeItem get_parent() const

Returns the parent TreeItem or a null object if there is none.

get_prev

TreeItem get_prev()

Returns the previous sibling TreeItem in the tree or a null object if there is none.

get_prev_in_tree

TreeItem get_prev_in_tree(wrap: bool = false)

Returns the previous TreeItem in the tree (in the context of a depth-first search) or a null object if there is none.

If wrap is enabled, the method will wrap around to the last element in the tree when called on the first visible element, otherwise it returns null.

get_prev_visible

TreeItem get_prev_visible(wrap: bool = false)

Returns the previous visible sibling TreeItem in the tree (in the context of a depth-first search) or a null object if there is none.

If wrap is enabled, the method will wrap around to the last visible element in the tree when called on the first visible element, otherwise it returns null.

get_range

float get_range(column: int) const

Returns the value of a CELL_MODE_RANGE column.

get_range_config

Dictionary get_range_config(column: int)

Returns a dictionary containing the range parameters for a given column. The keys are “min”, “max”, “step”, and “expr”.

get_structured_text_bidi_override

TextSystem.StructuredTextParser get_structured_text_bidi_override(column: int) const

Returns the BiDi algorithm override set for this cell.

get_structured_text_bidi_override_options

Array get_structured_text_bidi_override_options(column: int) const

Returns the additional BiDi options set for this cell.

get_suffix

String get_suffix(column: int) const

Gets the suffix string shown after the column value.

get_text

String get_text(column: int) const

Returns the given column’s text.

get_text_alignment

HorizontalAlignment get_text_alignment(column: int) const

Returns the given column’s text alignment.

get_text_direction

Control.TextDirection get_text_direction(column: int) const

Returns item’s text base writing direction.

get_text_overrun_behavior

TextSystem.OverrunBehavior get_text_overrun_behavior(column: int) const

Returns the clipping behavior when the text exceeds the item’s bounding rectangle in the given column. By default it is TextSystem.OVERRUN_TRIM_ELLIPSIS.

get_tooltip_text

String get_tooltip_text(column: int) const

Returns the given column’s tooltip text.

get_tree

Tree get_tree() const

Returns the Tree that owns this TreeItem.

is_accepting_children

bool is_accepting_children() const

Returns true if this TreeItem is allowed to accept children.

is_any_collapsed

bool is_any_collapsed(only_visible: bool = false)

Returns true if this TreeItem, or any of its descendants, is collapsed.

If only_visible is true it ignores non-visible TreeItems.

is_button_disabled

bool is_button_disabled(column: int, button_index: int) const

Returns true if the button at index button_index for the given column is disabled.

is_checked

bool is_checked(column: int) const

Returns true if the given column is checked.

is_custom_set_as_button

bool is_custom_set_as_button(column: int) const

Returns true if the cell was made into a button with set_custom_as_button().

is_edit_multiline

bool is_edit_multiline(column: int) const

Returns true if the given column is multiline editable.

is_editable

bool is_editable(column: int)

Returns true if the given column is editable.

is_indeterminate

bool is_indeterminate(column: int) const

Returns true if the given column is indeterminate.

is_selectable

bool is_selectable(column: int) const

Returns true if the given column is selectable.

is_selected

bool is_selected(column: int)

Returns true if the given column is selected.

is_visible_in_tree

bool is_visible_in_tree() const

Returns true if visible is true and all its ancestors are also visible.

move_after

void move_after(item: TreeItem)

Moves this TreeItem right after the given item.

Note: You can’t move to the root or move the root.

move_before

void move_before(item: TreeItem)

Moves this TreeItem right before the given item.

Note: You can’t move to the root or move the root.

propagate_check

void propagate_check(column: int, emit_signal: bool = true)

Propagates this item’s checked status to its children and parents for the given column. It is possible to process the items affected by this method call by connecting to Tree.check_propagated_to_item. The order that the items affected will be processed is as follows: the item invoking this method, children of that item, and finally parents of that item. If emit_signal is false, then Tree.check_propagated_to_item will not be emitted.

remove_child

void remove_child(child: TreeItem)

Removes the given child TreeItem and all its children from the Tree. Note that it doesn’t free the item from memory, so it can be reused later (see add_child()). To completely remove a TreeItem use Object.free().

Note: If you want to move a child from one Tree to another, then instead of removing and adding it manually you can use move_before() or move_after().

select

void select(column: int, set_as_cursor: bool = true)

Selects the given column. If set_as_cursor is true, the Tree’s cursor will be moved to this item (only matters if Tree.select_mode is set to Tree.SELECT_MULTI).

set_accept_children

void set_accept_children(allowed: bool)

Sets TreeItem’s ability to accept children.

set_auto_translate_mode

void set_auto_translate_mode(column: int, mode: Entity.AutoTranslateMode)

Sets the given column’s auto translate mode to mode.

All columns use Entity.AUTO_TRANSLATE_MODE_INHERIT by default, which uses the same auto translate mode as the Tree itself.

set_autowrap_mode

void set_autowrap_mode(column: int, autowrap_mode: TextSystem.AutowrapMode)

Sets the autowrap mode in the given column. If set to something other than TextSystem.AUTOWRAP_OFF, the text gets wrapped inside the cell’s bounding rectangle.

set_autowrap_trim_flags

void set_autowrap_trim_flags(column: int, flags: BitField[TextSystem.LineBreakFlag])

Sets the autowrap trim flags for the given column. These flags control whether leading and trailing spaces are trimmed on wrapped lines. Set to 0 to disable all trimming.

set_button

void set_button(column: int, button_index: int, button: Texture2D)

Sets the given column’s button Texture2D at index button_index to button.

set_button_color

void set_button_color(column: int, button_index: int, color: Color)

Sets the given column’s button color at index button_index to color.

set_button_description

void set_button_description(column: int, button_index: int, description: String)

Sets the given column’s button description at index button_index for assistive apps.

set_button_disabled

void set_button_disabled(column: int, button_index: int, disabled: bool)

If true, disables the button at index button_index in the given column.

set_button_tooltip_text

void set_button_tooltip_text(column: int, button_index: int, tooltip: String)

Sets the tooltip text for the button at index button_index in the given column.

set_cell_mode

void set_cell_mode(column: int, mode: TreeCellMode)

Sets the given column’s cell mode to mode. This determines how the cell is displayed and edited.

set_checked

void set_checked(column: int, checked: bool)

If checked is true, the given column is checked. Clears column’s indeterminate status.

set_collapsed_recursive

void set_collapsed_recursive(enable: bool)

Collapses or uncollapses this TreeItem and all the descendants of this item.

set_custom_as_button

void set_custom_as_button(column: int, enable: bool)

Makes a cell with CELL_MODE_CUSTOM display as a non-flat button with a StyleBox.

set_custom_bg_color

void set_custom_bg_color(column: int, color: Color, just_outline: bool = false)

Sets the given column’s custom background color and whether to just use it as an outline.

Note: If a custom StyleBox is set, the background color will be drawn behind it.

set_custom_color

void set_custom_color(column: int, color: Color)

Sets the given column’s custom color.

set_custom_draw_callback

void set_custom_draw_callback(column: int, callback: Callable)

Sets the given column’s custom draw callback. Use an empty Callable (Callable()) to clear the custom callback. The cell has to be in CELL_MODE_CUSTOM to use this feature.

The callback should accept two arguments: the TreeItem that is drawn and its position and size as a Rect2.

To draw custom content over the native style, please use Tree.get_custom_drawing_canvas_item().

set_custom_font

void set_custom_font(column: int, font: Font)

Sets custom font used to draw text in the given column.

set_custom_font_size

void set_custom_font_size(column: int, font_size: int)

Sets custom font size used to draw text in the given column.

set_custom_stylebox

void set_custom_stylebox(column: int, stylebox: StyleBox)

Sets the given column’s custom StyleBox used to draw the background.

Note: If a custom background color is set, the StyleBox will be drawn in front of it.

set_description

void set_description(column: int, description: String)

Sets the given column’s description for assistive apps.

set_edit_multiline

void set_edit_multiline(column: int, multiline: bool)

If multiline is true, the given column is multiline editable.

Note: This option only affects the type of control (LineEdit or TextEdit) that appears when editing the column. You can set multiline values with set_text() even if the column is not multiline editable.

set_editable

void set_editable(column: int, enabled: bool)

If enabled is true, the given column is editable.

set_expand_right

void set_expand_right(column: int, enable: bool)

If enable is true, the given column is expanded to the right.

set_icon

void set_icon(column: int, texture: Texture2D)

Sets the given cell’s icon Texture2D. If the cell is in CELL_MODE_ICON mode, the icon is displayed in the center of the cell. Otherwise, the icon is displayed before the cell’s text. CELL_MODE_RANGE does not display an icon.

set_icon_max_width

void set_icon_max_width(column: int, width: int)

Sets the maximum allowed width of the icon in the given column. This limit is applied on top of the default size of the icon and on top of Tree.icon_max_width. The height is adjusted according to the icon’s ratio.

set_icon_modulate

void set_icon_modulate(column: int, modulate: Color)

Modulates the given column’s icon with modulate.

set_icon_overlay

void set_icon_overlay(column: int, texture: Texture2D)

Sets the given cell’s icon overlay Texture2D. The cell has to be in CELL_MODE_ICON mode, and icon has to be set. Overlay is drawn on top of icon, in the bottom left corner.

set_icon_region

void set_icon_region(column: int, region: Rect2)

Sets the given column’s icon’s texture region.

set_indeterminate

void set_indeterminate(column: int, indeterminate: bool)

If indeterminate is true, the given column is marked indeterminate.

Note: If set true from false, then column is cleared of checked status.

set_language

void set_language(column: int, language: String)

Sets the language code of the given column’s text to language. This is used for line-breaking and text shaping algorithms. If language is empty, the current locale is used.

set_metadata

void set_metadata(column: int, meta: Variant)

Sets the metadata value for the given column, which can be retrieved later using get_metadata(). This can be used, for example, to store a reference to the original data.

set_range

void set_range(column: int, value: float)

Sets the value of a CELL_MODE_RANGE column.

set_range_config

void set_range_config(column: int, min: float, max: float, step: float, expr: bool = false)

Sets the range of accepted values for a column. The column must be in the CELL_MODE_RANGE mode.

If expr is true, the edit mode slider will use an exponential scale as with Range.exp_edit.

set_selectable

void set_selectable(column: int, selectable: bool)

If selectable is true, the given column is selectable.

set_structured_text_bidi_override

void set_structured_text_bidi_override(column: int, parser: TextSystem.StructuredTextParser)

Set BiDi algorithm override for the structured text. Has effect for cells that display text.

set_structured_text_bidi_override_options

void set_structured_text_bidi_override_options(column: int, args: Array)

Set additional options for BiDi override. Has effect for cells that display text.

set_suffix

void set_suffix(column: int, text: String)

Sets a string to be shown after a column’s value (for example, a unit abbreviation).

set_text

void set_text(column: int, text: String)

Sets the given column’s text value.

set_text_alignment

void set_text_alignment(column: int, text_alignment: HorizontalAlignment)

Sets the given column’s text alignment to text_alignment.

set_text_direction

void set_text_direction(column: int, direction: Control.TextDirection)

Sets item’s text base writing direction.

set_text_overrun_behavior

void set_text_overrun_behavior(column: int, overrun_behavior: TextSystem.OverrunBehavior)

Sets the clipping behavior when the text exceeds the item’s bounding rectangle in the given column.

set_tooltip_text

void set_tooltip_text(column: int, tooltip: String)

Sets the given column’s tooltip text.

uncollapse_tree

void uncollapse_tree()

Uncollapses all TreeItems necessary to reveal this TreeItem, i.e. all ancestor TreeItems.