mouseEnter disabled when another component starts Drag?


I’ve several component put together with the Jucer. I noticed that the mouseEnter calls are ‘disabled’ while I’m dragging from another component. IE : I drag out from component A, and I want component B to be send a mouseEnter notification when the mouse enter it, but I can’t get anything.

I would like the component to interacts each others while dragging, so what is the best way to do so ?



Yes, you always want the comp that’s being dragged to receive the messages until the mouse is released. But it’s simple to make that component do the appropriate thing based on which other comp the mouse is over, or use the DragAndDropTarget classes to do it for you.

1 Like

I actually tried isMouseOver() in a timer callback, but it does not trigger either while dragging.

So I put a timer on all component, and used getMouseXYRelative(x,y) and contain(x,y) to do the appropriate test, now it’s working…

Thanks a lot,


If you’re dragging from component A, then you should probably be using component A’s mouseDrag callback. Using a timer sounds like a bit of a bodge to me.

are you just talking about dragging the mouse from one component to another, or are you talking about dragging a component from one to another? [because if its the latter, then the mouse will always be over the component that is being dragged]

Yes, drag from one component to another.

Yes, however in this (A) mouseDrag callback, how do I know which of the (B) component is draged over ? And then how is it possible to ‘inform’ B that it is beeing dragged over without using a timer inside B ?


Yes, drag from one component to another.

ha! your response doesn’t quite answer the question…

Q: Is it type [A] from one to another or type [B] from one to another?
A: Yes, from one to another.

:slight_smile: I’m going to assume that you mean version A (where you’re not dragging anything, just the mouse).

there’s Component::getComponentUnderMouse() which will return the component currently under the mouse, if you haven’t tried that yet it could be what you’re after. Using timers to do this will only upset you later down the line, as it’s a bodge and a half.

Apologies for re-invoking such an old post, but I’m having a very similar issue:

I have a row of buttons that, in between mouseDown and mouseUp events, repaint the button that the mouse is currently over. I do this by calling repaint() in the mouseDrag function. The problem is that getComponentUnderMouse() always returns the Component where the event was sent from:

void MyButton::mouseDrag(const MouseEvent& e)
    MyButton* c = dynamic_cast<MyButton*> (e.source.getComponentUnderMouse());
    if(c && c != this)
         c->repaint(); // never called, as c is always this.

Does the MouseInputSource ‘source’ only pertain to the origin of the mouse event? If so, how do I modify MouseInputSource, such that getComponentUnderMouse() returns the Component that the mouse is actually under?

Thanks in advance,

Component::getComponentAt() ?

Overlooked that one! Got it working by first getting the parent component and then parent->getComponentAt(relX, relY).