@@ -2544,14 +2544,14 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
25442544 Point2i button_ofs = Point2i (ofs + item_width_with_buttons - button_size.width , p_pos.y ) - theme_cache.offset + p_draw_ofs;
25452545
25462546 bool should_draw_pressed = cache.click_type == Cache::CLICK_BUTTON && cache.click_item == p_item && cache.click_column == i && cache.click_index == j && !p_item->cells [i].buttons [j].disabled ;
2547- bool should_draw_hovered = !should_draw_pressed && ! drop_mode_flags && cache.hover_item == p_item && cache.hover_column == i && cache.hover_button_index_in_column == j && !p_item->cells [i].buttons [j].disabled ;
2547+ bool should_draw_hovered = !drop_mode_flags && cache.hover_item == p_item && cache.hover_column == i && cache.hover_button_index_in_column == j && !p_item->cells [i].buttons [j].disabled ;
25482548
25492549 if (should_draw_pressed || should_draw_hovered) {
25502550 Point2 od = button_ofs;
25512551 if (rtl) {
25522552 od.x = get_size ().width - od.x - button_size.x ;
25532553 }
2554- if (should_draw_pressed) {
2554+ if (should_draw_pressed && should_draw_hovered ) {
25552555 theme_cache.button_pressed ->draw (get_canvas_item (), Rect2 (od.x , od.y , button_size.width , MAX (button_size.height , label_h)));
25562556 } else {
25572557 theme_cache.button_hover ->draw (get_canvas_item (), Rect2 (od.x , od.y , button_size.width , MAX (button_size.height , label_h)));
@@ -3831,9 +3831,16 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
38313831 }
38323832
38333833 if (cache.click_type == Cache::CLICK_BUTTON && cache.click_item != nullptr ) {
3834- // make sure in case of wrong reference after reconstructing whole TreeItems
3834+ // Make sure the reference is current in case TreeItems is reconstructed.
38353835 cache.click_item = get_item_at_position (cache.click_pos );
3836- emit_signal (" button_clicked" , cache.click_item , cache.click_column , cache.click_id , mb->get_button_index ());
3836+
3837+ // Only emit the event if the click is still within the button rect.
3838+ TreeItem *current_item;
3839+ int current_column, current_index, current_section;
3840+ _find_button_at_pos (mb->get_position (), current_item, current_column, current_index, current_section);
3841+ if (current_item == cache.click_item && current_column == cache.click_column && current_index == cache.click_index ) {
3842+ emit_signal (" button_clicked" , cache.click_item , cache.click_column , cache.click_id , mb->get_button_index ());
3843+ }
38373844 }
38383845
38393846 cache.click_type = Cache::CLICK_NONE;
0 commit comments