NSView | NSTextField右键问题

发布于 2024-10-18 16:41:16 字数 387 浏览 1 评论 0原文

我有一个 NSView,里面有一个 Label : NSTextField Control, 在 NSView 内部,我必须在右键单击时显示一个上下文菜单,它工作正常,除了下面的几个问题,

在某些地方它不起作用,即如果我右键单击,它不会打开上下文菜单,进一步我意识到我保持标签的长度/宽度太大,并且在标签上单击鼠标右键, 但由于这是空白区域,因此根据用户体验,它应该允许打开上下文菜单,我觉得有两种方法可以解决此问题

1 - 检查 NSTextField 运行时的宽度/长度以设置正确的宽度,

2 - 将鼠标事件(或至少右键单击)从 NSTextField(标签)传递到其 ParentView,

任何人都可以建议我,我怎样才能实现这一点?

亲切的问候

罗汉

I have a NSView and inside that, there is a Label : NSTextField Control,
Inside NSView i have to show a context menu on the right click, its working fine except few below issue,

At some place it didn't work, i.e. if i do right click , it doesn't open the Context Menu, further i realized i have kept length/Width of Label is too big and right click happening over the Label,
but since this is the empty area, so as par user experience, it should allow to open the context menu, i feel following two approaches to solve this problem

1 -- Check the width/Length of the NSTextField runtime to set the proper width,

2 -- Pass Mouse event ( or at-least Right-click )from NSTextField( Label ) to its ParentView,

Can anyone suggest me, how can i achieve that ?

Kind Regards

Rohan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单调的奢华 2024-10-25 16:41:16

我不确定这是否有帮助,但是当您在界面生成器中的 nstextfield 上单击鼠标右键时,您将看到一个“菜单”对象。将其与 NSMenu 连接,您将拥有一个默认的上下文菜单。

I'm not sure if this helps but when you click with the right mouse button on the nstextfield in the Interface Builder you'll see a "menu" object. Connecting this with a NSMenu and you have a default context menu.

甜柠檬 2024-10-25 16:41:16

到目前为止,它与以下代码一起工作,

-(void)initSubViews{
/* 在此函数中只需初始化子视图 */
NSSize imageSize = [pStatusImage 大小];

pStatusImageView = [[NSImageView alloc]initWithFrame:NSMakeRect(0, 0,     
                         imageSize.width,imageSize.height)];

pDisplayName = [[NSTextField alloc]initWithFrame:NSMakeRect(0, 0,          
                    STATUS_WIDTH,STATUS_HEIGHT)];
[pDisplayName becomeFirstResponder];

**[pDisplayName setMenu:pCTTableMenu];**

    ..........................................................
    ..........................................................
    ..........................................................

这样

我就可以在右键单击时看到菜单,

亲切的问候
罗汉

So far its working with following piece of code,

-(void)initSubViews{
/* In this function just init the sub-views */
NSSize imageSize = [pStatusImage size];

pStatusImageView = [[NSImageView alloc]initWithFrame:NSMakeRect(0, 0,     
                         imageSize.width,imageSize.height)];

pDisplayName = [[NSTextField alloc]initWithFrame:NSMakeRect(0, 0,          
                    STATUS_WIDTH,STATUS_HEIGHT)];
[pDisplayName becomeFirstResponder];

**[pDisplayName setMenu:pCTTableMenu];**

    ..........................................................
    ..........................................................
    ..........................................................

}

so i can able to see the menu on the right click,

Kind Regards
Rohan

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文