diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 46a26125893..1b44e48c5b7 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -6404,14 +6404,15 @@ String Tree::get_tooltip(const Point2 &p_pos) const { // Walk forwards until we know which column we're in. int next_edge = 0; int i = 0; - for (; i < columns.size(); i++) { + for (const ColumnInfo &column : columns) { + next_edge += get_column_width(i++); + if (pos_x < next_edge) { + if (!column.title_tooltip.is_empty()) { + return column.title_tooltip; + } break; } - next_edge += get_column_width(i); - } - if (!columns[i - 1].title_tooltip.is_empty()) { - return columns[i - 1].title_tooltip; } // If the column has no tooltip, use the default.