Change appearance of items that are being dragged over in treeview

Hey everyone,

Im creating an application that uses TreeView and TreeViewItem classes to represent a folder structure with files in it. I have implemented drag and drop behaviour by overriding getDragSourceDescription(), and itemDropped(). I’m using createItemComponent() to supply custom components to the treeview.

My question is: Is it possible to change the appearance of the items when they are being dragged over? Because TreeViewItem does not have virtual itemDragEnter() and itemDragExit() there does not seem to be a straighforward way. I’ve looked at Juce’s InsertPointHighlight and TargetGroupHighlight classes inside TreeView but they don’t allow for any customization either.

Treeview is not supposed to be inherited, so there is no chance of adding code to the itemDragEnter() and itemDragExit() there either. I have no idea how to approach this problem.
Thanks for your help.

https://docs.juce.com/develop/classDragAndDropContainer.html#a93ca5a96ca48251f5b8a5f79d3d808c6

change the image that gets shown. most folks use createComponentSnapshot() but you could supply some other image.

I don’t mean the image that is being dragged, but the elements of the tree that are being dragged over. The crux of the problem is that i have no way of letting these components know when they are being dragged over, because juce’s TreeViewitem doesn’t actually inherit DragAndDropTarget

maybe you’ll find some solution here: ListBox Drag-To-Reorder [Solved]

It’s not the treeview class, but it’s similar.

I think your problem is, that the TreeViewItem is actually not a component. It also confused me the first time, I saw it.

But one solution: you have the function TreeViewItem::createItemComponent(). It lets you create a component, which you can use to display your TreeViewItem. And this component can be a DragAndDropTarget and can react to things being dragged over it.

Hi,


If you are talking about the customization of this component ( InsertPointHighlight and TargetGroupHighlight ) i have the same problem.
I want to change the apparance of the line that indicates where the item will be dropped but the paint() logic is embedded in these classes InsertPointHighlight and TargetGroupHighlight and there is not way to deal with it.
Even with JUCE 7.0.2 this “problem” is still present.
Any kind of ideas ?

1 Like