How to replace the default dnd image in TableListBox

Hey Jules

Is there a way to set a custom image when things are dragged from a TableListBox.

I tried a hacky way by catching the drag in my main content component by overriding the startDragging method (thought this would get called by the TableList and I could swap that image with my custom one), but that never gets called.
What’s the right solution for this?

Thanks

You would have to call that method from your TableListBox on mouse drag. startDragging, isn’t a virtual method so it wouldn’t get called. You just have to call the method and give it required data.

void Picker::mouseDrag (const juce::MouseEvent &e)
{
		juce::Image* pDragImage = juce::ImageFileFormat::loadFrom(juce::File(T("/image.jpg")));
		juce::DragAndDropContainer * dragContainer = NULL;
		dragContainer = juce::DragAndDropContainer::findParentDragContainerFor(this);
		if(dragContainer!=0)
		{			
			dragContainer->startDragging (DRAGEFFECTDESCRIPTION, static_cast<juce::Component*>(this), pDragImage);
		}
		setMouseCursor(juce::MouseCursor::DraggingHandCursor);
	}
}

Thanks vishvesh

Yeah I figured that was the way to go… Got it working now.

One problem was that I couldn’t just use the TableListBox mouseDrag, had to listen to the actual RowComponent drag stuff (nested table list components) and filter out the header stuff.

void InstrumentTableListBox::mouseDrag (const MouseEvent& e) { if (e.eventComponent != this && e.eventComponent != getHeader() && getNumSelectedRows() >= 1 && isEnabled() && e.mouseWasClicked()) { ...

Also had to get the image drawn around the mouse cursor so that the cursor is right in the centre. Got it all working now, time for clean-up.
Thanks again.

Thanks.

Thanks.


I Haven't tried using this. I will give it a shot. Thanks for this.

I Haven’t tried using this. I will give it a shot. Thanks for this.

I guess Jules just added this.