Skip to content

Drag and drop on tree node #2638

@Kinou2212

Description

@Kinou2212

Version of Dear PyGui

Version: 2.3.0
Operating System: Windows 11

My Issue/Question

I used treenode to build a file browser with drag-and-drop functionality for moving files. I found that I cannot drag and drop the widget into a treenode that contains its parent treenode; it seems that the drop_callback is not being triggered correctly. Notice how the yellow highlight does not appear on uncle treenodes.

To Reproduce

Steps to reproduce the behavior:

  1. see video

Expected behavior

The widget should be put in the selected treenode.

Screenshots/Video

Video1.mp4

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport(width=600, height=500)
dpg.setup_dearpygui()


def drop_cb(s, a, u):
    dpg.move_item(a, parent=s)

with dpg.window(tag="test", width=500, height=400):
    with dpg.tree_node(label="tree_node A",
                       drop_callback=drop_cb, payload_type="TEST", ):
        dpg.add_selectable(label="select a")
        with dpg.drag_payload(parent=dpg.last_item(), drag_data=dpg.last_item(), payload_type="TEST"):
            dpg.add_button("a")

        with dpg.tree_node(label="tree_node B",
                           drop_callback=drop_cb, payload_type="TEST"):
            dpg.add_selectable(label="select b")
            with dpg.drag_payload(parent=dpg.last_item(), drag_data=dpg.last_item(), payload_type="TEST"):
                dpg.add_button("b")

    with dpg.tree_node(label="tree_node C",
                       drop_callback=drop_cb, payload_type="TEST"):
        dpg.add_selectable(label="select c")
        with dpg.drag_payload(parent=dpg.last_item(), drag_data=dpg.last_item(), payload_type="TEST"):
            dpg.add_button("c")

dpg.show_viewport()
dpg.set_primary_window("test", True)
dpg.start_dearpygui()
dpg.destroy_context()

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions