0

I have multiple NSTextFields and other controls embedded in custom views:

Custom View
- Image View
- Custom View
-- Text Field
-- Text Field
.
.
.
- Custom View
-- Text Field
-- Text Field
.
.
.

NSTextFields have assigned tooltips. These tooltips are not being displayed, mouse events are probably intercept by NSView. Is there any way how to pass the events through the nsview or other way how to make ntextfields' tooltips to be displayed?

2 Answers2

0

You could be doing several things that prevents tooltips, can't say without any code. But here is a worst case way to fix it if standard controls are buried deep inside views that could possibly be handing or eating default tooltips

In your custom view

[textField addToolTipRect:textField.frame owner:self userData:NULL];

and implement

-(NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data
{
    return textField.tooltip;
}
lead_the_zeppelin
  • 2,017
  • 13
  • 23
  • There is no custom code related to the issue. I have in xib defined numerous controls (majority of them are NSTextFields, which have associated tool tip. These controls were embedded in custom view in XCode (Editor->Embed In->Custom View) in order to be able to display/hide these views as necessary. After embedding the original tooltips can not be displayed, mouse 'move over' event is handled by embedding view and the view's tooltip is displayed. – user3530139 Apr 22 '14 at 13:02
0

If you have an NSBox *box that contains several NSTextFields in it, issue this, which includes first binding to, or otherwise setting, the tool tip for your box view, and then designating the tool tip rectangle as the box view's frame with the box view as owner and sending it to the box view:

[box bind:@"toolTip" toObject:myNSObjectControllerInstance withKeyPath:@"selection.something which is.my.box.tooltip.info.property.key.path" options:nil];
[box addToolTipRect:box.frame owner:box userData:NULL];

Hovering your mouse cursor over the text fields inside the box will show tool tips for the text fields. Hovering your mouse cursor over the box will show tool tips for the box... unless your mouse cursor is also inside (I guess the frame) of a nested subview of that box's view, and therefore the current tool tip level is already nested inside the box's view's view hierarchy:

The normal behavior with tool tips is to only traverse inwardly into embedded views, not outwardly back up to the superviews. This could be your problem here, because one must by default move the mouse outside a view and then back inside a view in order to see tool tips of that view hierarchy level -- once your mouse hovers over a nested view, even if that nested view lacks a tool tip, tool tips for that nested view's superview will not display until you have moved the mouse cursor outside the superview and back into the superview, without also entering any of its subviews. Note that the tool tip's nested index does not reset after the tool tip has vanished.

Maybe you can customize this with a subclass of NSView that has its own addToolTipRect:owner:userData: method. Check the toolTip-related Apple documentation and search The Internet for custom "toolTip" "NSView".

Sparky
  • 172
  • 15