I have 4 buttons. I need an action to occur on hover. How do I capture a mouseover event on a button?
You need to make an NSTrackingArea (using alloc()'s initWithRect_options_owner_userInfo_), add it to the view using addTrackingArea_, and then implement mouseEntered_ and mouseExited_ in the view (which means subclassing your button).
It’s a bit tedious, probably because it’s rarely a good thing to do UI-wise.
Sounds kinda painful. Maybe I’ll just pass by this learning experience
Thanks anyways!
If this is still relevant, see my thread where I had the same problem: http://macscripter.net/viewtopic.php?id=30746
Wow, that’s great. It’s not relevant for my current project but it’s much more relevant on an upcoming project. Thanks for the great link.
If I were doing it today, I’d probably suggest something more like:
set trackingArea to current application's NSTrackingArea's ¬
alloc()'s initWithRect_options_owner_userInfo_(missing value, ¬
(current application's NSTrackingInVisibleRect as integer) + ¬
(current application's NSTrackingActiveInKeyWindow as integer) + ¬
(current application's NSTrackingMouseEnteredAndExited as integer), ¬
me, missing value)
tell my custView to addTrackingArea_(trackingArea)
More verbose, but more useful to understand than using 545.