5

I am developing an application with several windows and views (NSTextView, etc.).

I would like to change the cursor globally in my application, so that even if the cursor enters the trackingRect of (for instance) an NSTextView it does not change.

Is this possible?


PS: I need also to revert back to the usual behaviour.

Colas
  • 3,473
  • 4
  • 29
  • 68
  • If you're asking for a switch you can turn off and on to make a specific cursor show up on any view, that does not exist. You have to subclass each view and override the appropriate methods. – rocky Feb 09 '17 at 08:27
  • Ah... how could I disable the change of cursor for a set of views? (NSTextView, PDFView, etc.) Is it do you think achievable without subclassing? – Colas Feb 09 '17 at 09:57

1 Answers1

2

Yes this is possible. I had an almost similar requirement, and here is how I solved it:

When creating a window, create a transparent view with the same frame as that of the window. Then add a cursor rect to the view (that extends to the latter's bounds) for your specific cursor. Finally add it as the last subview of the window's contentView, so that it acts as an overlay. When this overlay is present, cursor rects of underlying views are not activated.

See https://stackoverflow.com/a/43886799/7908996 for detailed instructions and working code (read the window's contentView instead of WebView). It also describes how to revert back to the usual behaviour.

Hope that helps! :)

Community
  • 1
  • 1
Shiva Prasad
  • 106
  • 12