Change appearance of items that are being dragged over in treeview

#1

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.

#2

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.

#3

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

#4

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

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

#5

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.