Trouble with Cursor Change on Button Object


Is there a reason that my cursor doesn't change when I'm clicking on a button and dragging, vs clicking next to a button and dragging? In either case, it prints "What a drag" to the output file, so I know the listener is actually being called. I'm on OSX, but I wouldn't expect that to be relevant.

void MappingEditor::mouseDrag(const MouseEvent &event){
  DebugWriter::write("What a drag");

Thank you!


Hmmm... I think your parent component shouldn't be getting mouseDrag events when you click on a button, keep the mouse button pressed and then drag. Only the button should be getting the drag events. If you click next to the button and then drag, the parent component will get the drag events. I just tested your code on Windows, linux and OS X and only saw "what a drag" when dragging outside of the button.


The reason is that it gets it is because I did my_button.addMouseListener(this, false) inside of the parent, I imagine. That way, I can get the events for all the modules/sliders inside of my component (MappingEditor, in this case) and use if (event.eventComponent == &each_component) to pick them apart. Is this not the design intention? Of course, I could make subclasses for every slider and button that I want to behave in a certain way, but that seems like a really verbose way to do this. 

I am interested to know what you consider the right way to do this to be, but the fact that my button was still responding to the listener was not something that I considered to be a problem. The lack of cursor change even though the listener code was being executed is what I find to be more concerning.

Thanks again.


Hi Chet, reading the setMouseCursor documentation, it says that it will change the cursor everytime the mouse is over the component, i.e. you only need to call setMousrCursor once and it will change everytime the mouse enters the component. A TextButton however, internally also calls setMouseCursor with an arrow cursor and thus, when your cursor enters the TextButton it will change back to an arrow. I think this is intended behaviour as sub-components should be able to override the cursor of their parents. To get what you want, simply call setMouseCursor on the button as well:

setMouseCursor (MouseCursor::DraggingHandCursor);

my_button.setMouseCursor (MouseCursor::DraggingHandCursor);

DBG ("What a drag");

Does this work for you?


Yes it does. Thanks, Fabian.


Thanks, was having a similar problem