Problem hiding cursor in Component::mouseDown


I’m trying to hide the cursor when I click a component, but the problem is that the cursor doesn’t dissapear until I release the left mouse button, and I get an ugly effect because the cursor must move to another place.

[code]void BotonZoom::mouseDown(const MouseEvent &e)



What could I do?



  e.source.enableUnboundedMouseMovement (true);

in your mouseDown() instead of those two lines of code you have.


Thanks! It seems to do what I wanted do in first place! :smiley:

btw, is there any easy method to limit the mouse movement after use this command?


What do you mean limit the mouse movement? At this point the cursor is invisible. When the mouse button is released, the cursor should appear somewhere inside your component. What exactly are you trying to do?


I’m trying to create an special zoom button. If you drag it up/down you get vertical zoom (and a button animation), left/right horizontal zoom, and something between mixed vertical & horizontal zoom. The zoom goes from 0.25x to 4.00x, it’s limited with a basic if secuence.

The problem with enableUnboundedMouseMovement is that movement is totally unrestricted (= unlimited), so if you drag the button and adjust the zoom at 4.00x and you continue dragging your mouse, let’s say, one meter, you must move the mouse one meter back again if you want to reduce the zoom again.

I think I’m going to use in mouse down method:

void BotonZoom::mouseDown(const MouseEvent &e) { e.source.hideCursor(); // Thanks to you, TheVinn, I learnt about this class setMouseCursor(MouseCursor::NoCursor); }

And then restrict the mouse movement in mouse drag. In mouse up I’ll return the cursor to the last clicked point.


Yes, I understand exactly your problem. When the mouse goes beyond the limit 4x, and the user changes direction, you dont want to wait for the mouse to come back, you want to immediately begin reducing the zoom from 4x. I address this exact behavior in my custom slider (which also functions as a knob). Consider the following code:

void CustomSlider::mouseDrag (const MouseEvent& e)
  if (m_bEnableUnboundedMouseMovement)
    e.source.enableUnboundedMouseMovement( true );

  double value;

  switch( m_style )
  case styleVertical:
    value = m_startValue
      + e.getDistanceFromDragStartX()/1500.
      - e.getDistanceFromDragStartY()/250.;

  case styleHorizontal:
    value = m_startValue
      + e.getDistanceFromDragStartX()/250.
      - e.getDistanceFromDragStartY()/1500.;


  if( value > 1 )
    m_startValue -= value - 1;
    value = 1;
  else if( value < 0 )
    m_startValue -= value;
    value = 0;

  notifySetValue( value );

m_startValue is the initial value of the control, saved in mouseDown. If you look at the “magic lines”, I address the case where the unbounded mouse would cause the value go to outside the range (-1 and 1 in my case, and for you it would be 0.25x and 4.00x).

In my control, no matter how far you push the mouse past the control value limit of 0…1, as soon as you reverse direction the control is immediately responsive - this, I believe, is exactly what you are asking for.


That’s what I was looking for! Thanks for your support and happy chrismas! :smiley:


This seems like a bug, have they fixed it in new versions yet?
Everyone wants the cursor to hide when dragging, and also respond immediately when changing direction.