Inherits: Control < CanvasItem < Node < Object

Category: Core

Brief Description

Control to show a tree of items.


bool allow_reselect false
bool allow_rmb_select false
int columns 1
int drop_mode_flags 0
FocusMode focus_mode O: 2
bool hide_folding false
bool hide_root false
bool rect_clip_content O: true
SelectMode select_mode 0


bool are_column_titles_visible ( ) const
void clear ( )
TreeItem create_item ( Object parent=null, int idx=-1 )
void ensure_cursor_is_visible ( )
int get_column_at_position ( Vector2 position ) const
String get_column_title ( int column ) const
int get_column_width ( int column ) const
Rect2 get_custom_popup_rect ( ) const
int get_drop_section_at_position ( Vector2 position ) const
TreeItem get_edited ( ) const
int get_edited_column ( ) const
Rect2 get_item_area_rect ( Object item, int column=-1 ) const
TreeItem get_item_at_position ( Vector2 position ) const
TreeItem get_next_selected ( Object from )
int get_pressed_button ( ) const
TreeItem get_root ( )
Vector2 get_scroll ( ) const
TreeItem get_selected ( ) const
int get_selected_column ( ) const
void set_column_expand ( int column, bool expand )
void set_column_min_width ( int column, int min_width )
void set_column_title ( int column, String title )
void set_column_titles_visible ( bool visible )

Theme Properties

Texture arrow  
Texture arrow_collapsed  
StyleBox bg  
StyleBox bg_focus  
int button_margin 4
StyleBox button_pressed  
Texture checked  
StyleBox cursor  
Color cursor_color Color( 0, 0, 0, 1 )
StyleBox cursor_unfocused  
StyleBox custom_button  
Color custom_button_font_highlight Color( 0.94, 0.94, 0.94, 1 )
StyleBox custom_button_hover  
StyleBox custom_button_pressed  
int draw_guides 1
int draw_relationship_lines 0
Color drop_position_color Color( 1, 0.3, 0.2, 1 )
Font font  
Color font_color Color( 0.69, 0.69, 0.69, 1 )
Color font_color_selected Color( 1, 1, 1, 1 )
Color guide_color Color( 0, 0, 0, 0.1 )
int hseparation 4
int item_margin 12
Color relationship_line_color Color( 0.27, 0.27, 0.27, 1 )
int scroll_border 4
int scroll_speed 12
Texture select_arrow  
StyleBox selected  
StyleBox selected_focus  
Color selection_color Color( 0.1, 0.1, 1, 0.8 )
Color title_button_color Color( 0.88, 0.88, 0.88, 1 )
Font title_button_font  
StyleBox title_button_hover  
StyleBox title_button_normal  
StyleBox title_button_pressed  
Texture unchecked  
Texture updown  
int vseparation 4


Emitted when a button on the tree was pressed (see TreeItem.add_button).

  • cell_selected ( )

Emitted when a cell is selected.

  • column_title_pressed ( int column )

Emitted when a column’s title is pressed.

  • custom_popup_edited ( bool arrow_clicked )

Emitted when a cell with the TreeItem.CELL_MODE_CUSTOM is clicked to be edited.

  • empty_tree_rmb_selected ( Vector2 position )

Emitted when the right mouse button is pressed if right mouse button selection is active and the tree is empty.

  • item_activated ( )

Emitted when an item’s label is double-clicked.

Emitted when an item is collapsed by a click on the folding arrow.

  • item_custom_button_pressed ( )

  • item_double_clicked ( )

Emitted when an item’s icon is double-clicked.

  • item_edited ( )

Emitted when an item is edited.

  • item_rmb_edited ( )

Emitted when an item is edited using the right mouse button.

  • item_rmb_selected ( Vector2 position )

Emitted when an item is selected with the right mouse button.

  • item_selected ( )

Emitted when an item is selected.

Emitted instead of item_selected if select_mode is SELECT_MULTI.

  • nothing_selected ( )


enum SelectMode:

  • SELECT_SINGLE = 0 — Allows selection of a single item at a time.
  • SELECT_ROW = 1
  • SELECT_MULTI = 2 — Allows selection of multiple items at the same time.

enum DropModeFlags:



This shows a tree of items that can be selected, expanded and collapsed. The tree can have multiple columns with custom controls like text editing, buttons and popups. It can be useful for structured displays and interactions.

Trees are built via code, using TreeItem objects to create the structure. They have a single root but multiple roots can be simulated if a dummy hidden root is added.

func _ready():
    var tree =
    var root = tree.create_item()
    var child1 = tree.create_item(root)
    var child2 = tree.create_item(root)
    var subchild1 = tree.create_item(child1)
    subchild1.set_text(0, "Subchild1")

To iterate over all the TreeItem objects in a Tree object, use TreeItem.get_next and TreeItem.get_children after getting the root through get_root.

Property Descriptions

  • bool allow_reselect
Default false
Setter set_allow_reselect(value)
Getter get_allow_reselect()

If true, the currently selected cell may be selected again.

  • bool allow_rmb_select
Default false
Setter set_allow_rmb_select(value)
Getter get_allow_rmb_select()

If true, a right mouse button click can select items.

Default 1
Setter set_columns(value)
Getter get_columns()

The number of columns.

  • int drop_mode_flags
Default 0
Setter set_drop_mode_flags(value)
Getter get_drop_mode_flags()

The drop mode as an OR combination of flags. See DropModeFlags constants. Once dropping is done, reverts to DROP_MODE_DISABLED. Setting this during Control.can_drop_data is recommended.

Default false
Setter set_hide_folding(value)
Getter is_folding_hidden()

If true, the folding arrow is hidden.

Default false
Setter set_hide_root(value)
Getter is_root_hidden()

If true, the tree’s root is hidden.

Default 0
Setter set_select_mode(value)
Getter get_select_mode()

Allows single or multiple selection. See the SelectMode constants.

Method Descriptions

  • bool are_column_titles_visible ( ) const

Returns true if the column titles are being shown.

  • void clear ( )

Clears the tree. This removes all items.

Create an item in the tree and add it as the last child of parent. If parent is null, it will be added as the root’s last child, or it’ll be the the root itself if the tree is empty.

  • void ensure_cursor_is_visible ( )

Makes the currently selected item visible. This will scroll the tree to make sure the selected item is visible.

  • int get_column_at_position ( Vector2 position ) const

Returns the column index under the given point.

  • String get_column_title ( int column ) const

Returns the column’s title.

  • int get_column_width ( int column ) const

Returns the column’s width in pixels.

  • Rect2 get_custom_popup_rect ( ) const

Returns the rectangle for custom popups. Helper to create custom cell controls that display a popup. See TreeItem.set_cell_mode.

  • int get_drop_section_at_position ( Vector2 position ) const

If drop_mode_flags includes DROP_MODE_INBETWEEN, returns -1 if position is the upper part of a tree item at that position, 1 for the lower part, and additionally 0 for the middle part if drop_mode_flags includes DROP_MODE_ON_ITEM.

Otherwise, returns 0. If there are no tree items at position, returns -100.

Returns the currently edited item. This is only available for custom cell mode.

  • int get_edited_column ( ) const

Returns the column for the currently edited item. This is only available for custom cell mode.

Returns the rectangle area for the specified item. If column is specified, only get the position and size of that column, otherwise get the rectangle containing all columns.

Returns the tree item at the specified position (relative to the tree origin position).

Returns the next selected item after the given one.

  • int get_pressed_button ( ) const

Returns the last pressed button’s index.

Returns the tree’s root item.

Returns the current scrolling position.

Returns the currently selected item.

  • int get_selected_column ( ) const

Returns the current selection’s column.

  • void set_column_expand ( int column, bool expand )

If true, the column will have the “Expand” flag of Control. Columns that have the “Expand” flag will use their “min_width” in a similar fashion to Control.size_flags_stretch_ratio.

  • void set_column_min_width ( int column, int min_width )

Sets the minimum width of a column. Columns that have the “Expand” flag will use their “min_width” in a similar fashion to Control.size_flags_stretch_ratio.

  • void set_column_title ( int column, String title )

Sets the title of a column.

  • void set_column_titles_visible ( bool visible )

If true, column titles are visible.