无法更改NSTextField的鼠标光标 [英] Can't change the mouse cursor of a NSTextField

查看:1043
本文介绍了无法更改NSTextField的鼠标光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在从NIB加载的窗口工作表中更改 NSTextField 的鼠标光标。

I'm trying to change the mouse cursor of a NSTextField in a window sheet, loaded from a NIB.

按照文档,我已经子类化了 NSTextField 并实现了 resetCursorRects

Following the documentation, I have subclassed NSTextField and implemented resetCursorRects.

- (void) resetCursorRects {
    [self addCursorRect:[self bounds] cursor:[NSCursor pointingHandCursor]];
}

这不会被调用。甚至在 NSWindowViewController 中添加以下内容后:

This is never called. Not even after adding the following in the NSWindowViewController:

- (void) windowDidLoad {
    [self.window invalidateCursorRectsForView:self.linkTextField];
}

我也尝试了跟踪区域,通过在 NSTextField 子类:

I also tried with a tracking area by adding the following in the NSTextField subclass:

- (void) awakeFromNib {
    NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
                                                 options:(NSTrackingCursorUpdate | NSTrackingActiveAlways)
                                                   owner:self
                                                userInfo:nil];
    [self addTrackingArea:trackingArea];
}

- (void)cursorUpdate:(NSEvent *)theEvent {
    [[NSCursor pointingHandCursor] set];
}

我做错了什么?

推荐答案

NSTextField的可点击链接

我在子类化之后工作了 NSTextField 如上所述:

I got this working after subclassing NSTextField as mentioned :

- (void)resetCursorRects {
    [self addCursorRect:[self bounds] cursor:[NSCursor pointingHandCursor]];
}

这篇关于无法更改NSTextField的鼠标光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆