Cocoa Application - Tooltip

ronenmagid1
ronenmagid1 used Ask the Experts™
on
On my Mac/Cocoa I'm programmatically displaying a bitmap - projecting it using using "drawInRect" onto one of my NSView instances.

I'd like this bitmap to have a tooltip.

As I'm new to Mac programming, I'd appreciate any pointer you may have.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You can find the info about the tooltips in Mac OS Reference Library:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/OnlineHelp/Concepts/Tooltips.html

Mainly, NSView contains few methods to work with the tooltips. setToolTip, addToolTipRect, removeAllToolTips, ... . NSWindow also has methods managing the tooltips:
http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#//apple_ref/doc/uid/20000013-SW44

Actually, almost all in the GUI part is derived from NSView and so almost everything supports the tooltip. It is very simple to assign a tooltip for a button. You can do it in the interface builder - in the identity inspector set the text you want to see. I attached few screenshots.

You will find a nice explanation and code here:
http://projects.autonomy.net.au/ai/chrome/site/resource/ebooks-programming/cocoa/cocoa-programming/0672322307_ch20lev1sec2.html
 

Screen-shot-2010-07-01-at-6.56.2.png
Screen-shot-2010-07-01-at-6.56.0.png

Author

Commented:
pgnatyuk: my bitmap is not a control, it's an arbitrary area on my view. Would this make creating a tooltip for this rectangle more complicated?

Commented:
I do not see your code. If it is about Cocoa (you make Mac OS application), and if you have only the window (NSWindow), I think, you need to make a custom view (NSView). NSView knows how to work with the tooltips. You will set all parameters and it will work. It is a bit late here to test right now. For any control, as you see, it is a trivial task to add a tooltip.

Have you read this article?
http://projects.autonomy.net.au/ai/chrome/site/resource/ebooks-programming/cocoa/cocoa-programming/0672322307_ch20lev1sec2.html

 

Commented:
Try this code:
[myView setToolTip:@"This is a test view"];

I didn't test it.

I took it from here:
http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg48345.html

Author

Commented:
Thanks. That did it.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial