简体   繁体   English

如何永久更改NSButton的光标?

[英]How can I permanently change the cursor for an NSButton?

I've set the cursor for my NSButton using the technique in this question , and that works great initially. 我已经使用这个问题中的技术为我的NSButton设置了光标,而且最初效果很好。 However, it breaks as soon as the window is hidden and then re-shown (this is a menubar app, so the window gets hidden every time the user clicks outside the window). 但是,一旦隐藏窗口然后重新显示它就会中断(这是一个菜单栏应用程序,因此每次用户在窗口外单击时窗口都会隐藏)。 At that point, it goes back to the normal cursor and will never go back to the pointing hand. 此时,它会返回到正常光标,并且永远不会返回到指针。

Is there a way to permanently set the cursor for an NSButton? 有没有办法永久设置NSButton的光标?


Update: 更新:
I've found that it isn't, so much, the showing/hiding of the window that kills the cursor as it is moving to another app and then moving back. 我发现窗口的显示/隐藏不是那么多,因为当它移动到另一个应用程序然后向后移动时会杀死光标。 If I simply show/hide the window, by clicking on the menubar icon over and over, the cursor always behaves. 如果我只是显示/隐藏窗口,通过反复点击菜单栏图标,光标始终表现。 But as soon as I click to another app and then click back, the cursor is forever broken (until I kill and re-start the app). 但是当我点击另一个应用程序然后再单击后,光标将永远被打破(直到我杀死并重新启动应用程序)。

I found that the problem was that the app was not being brought to the front when the user clicked on it. 我发现问题是当用户点击它时,应用程序没有被带到前面。 It was initially in the front, just after starting the app, but clicking away and then clicking back was making it appear in front, but it was NOT making it the "active window", for some reason. 它最初是在前面,刚刚启动应用程序之后,但是单击然后单击然后再将它显示在前面,但由于某种原因它并没有使它成为“活动窗口”。

I got around the issue by programmatically forcing it to the front using either 我通过编程方式使用其中任何一个来解决问题

[[NSApplication sharedApplication] activateIgnoringOtherApps : YES];

or 要么

[[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];

as pointed out in this question . 正如这个问题所指出的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM