Question

I'm trying to change the cursor when it passes over a view but I guess I am not coding it correctly as it is not working.

I have an appcontroller class and in it's .m file I have this

- (void) awakeFromNib { 

      //set up the cursors
      NSCursor * handCursor = [NSCursor closedHandCursor];

      //make a box
      Box* newBox = [[Box alloc] initWithFrame:NSMakeRect(10.0, 10.0, 100.0, 100.0)];
      //set up the rect for the cursor change
      NSRect rectForCursor = [newBox frame];
      [newBox addCursorRect:rectForCursor cursor:handCursor];
      //add box to main win
      [[mainWin contentView] addSubview:newBox];
}
Was it helpful?

Solution

You've forgotten to call [handCursor setOnMouseEntered:YES]. Otherwise, NSCursor will ignore the mouseEntered: event it is sent.

OTHER TIPS

Calling addCursorRect: from within awakeFromNib won't work. It must be called from within an override of resetCursorRects:, which is probably getting invoked at some point and clobbering the rect your set up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top