Setting the MouseCursor in a Drag and Drop Scenario [SOLVED]

Setting the MouseCursor on a DragAndDropTarget/FileDragAndDropTarget while items are being dragged does not work.

I could narrow it down to the part where the MouseInputSourceInternal::componentUnderMouse doesn’t gets updated while dragging.
Is this intended? When so, how can i archieve setting the mouse cursor in this scenario?

Yes, when you’re dragging, the mouse is captured by the component you clicked on, so it won’t attempt to look at any components that are being mouse-overed. But if you change the cursor of the original component, that should make it update.

That make sense for dragging JUCE components, but what is the original component for an external drag and drop coming from the finder/explorer?

Oh, I see… right. Bit more tricky then! I guess you could get the main MouseSource and then call showMouseCursor on it…?

That is working!

Thank you, Jules.

How do you get the “main” mouse source? I want to achieve the same, but don’t know how :frowning:

Have a look at:
MouseInputSource Desktop::getMainMouseSource ()const

1 Like

Hmmm I dont see that class method. Is it possible that I am using a universal API in my project an that desktop-only API is hidden?
I am new to JUCE…

EDIT: Ok I now understand getMainMouseSource is a method on Dekstop. But I don’t know how to initialise or somehow get access to a Desktop instance…

Access the desktop instance through juce::Desktop::getInstance().

Thank you!

Still having problems: Isn’;t the following suposed to work? placed on my Component class:

void SoundwaveRangeSelector::mouseMove(const MouseEvent &event)
{
    MouseCursor dragging = MouseCursor(juce::MouseCursor::StandardCursorType::DraggingHandCursor);
    Desktop::getInstance().getMainMouseSource().showMouseCursor(dragging);
}

void SoundwaveRangeSelector::mouseEnter(const MouseEvent &event)
{
    MouseCursor dragging = MouseCursor(juce::MouseCursor::StandardCursorType::DraggingHandCursor);
    Desktop::getInstance().getMainMouseSource().showMouseCursor(dragging);
}