Re: Table View and Tool Tips
Re: Table View and Tool Tips
- Subject: Re: Table View and Tool Tips
- From: Ryan Stevens <email@hidden>
- Date: Thu, 17 Oct 2002 12:19:03 -0700
On Thursday, October 17, 2002, at 11:15 AM, Ryan Stevens wrote:
On Thursday, October 17, 2002, at 05:50 AM, Andreas Mayer wrote:
Hello.
Did anyone manage to display tool tips for the cells of a table view?
I tried two different approaches, that both failed:
1. Setting the whole table view as tool tip rect using
addToolTipRect:owner:userData: and determining the cell in
view:stringForToolTip:point:userData:.
That way I'm able to show the correct tool tip. But it won't disappear
until I move the mouse outside the table view.
2. Tracking mouse movement with mouseMoved: and setting a new tool tip
rect for the cell under the mouse using addToolTipRect:owner:userData:
every time.
view:stringForToolTip:point:userData: does not get called. I suppose
this is because the mouse is already inside the rectangle when I
register it. (Besides, I get an error when trying to removeAllToolTips
and none are defined. But there seems to be no way to find out
beforehand.)
I can imagine a third approach:
3. Setting up tool tips rects for each single cell in the table view
and recreating all of them when the table view or one table column
changes size.
That seems a lot of overhead and will probably not be feasible for
large lists.
I could manage the tooltips myself with mouseMoved: and timers - if
there was a way to manually show and hide a tool tip. But I didn't
find a way to do it. A NSToolTip class would help. Looks like there's
not even a toolTipColor method.
If I was able to get this working I would be happy to make the
solution open source ...
As a 4th way...
Subclass NSCell.
Add a -view:stringForToolTip:point:userData: method.
Add a way to setup a tooltip, such as;
// what I used for testing...
- (void)resetTooltipForColumn:(int)column andRow:(int)row
inTableview:(NSTableView *)view
{
NSRect aRect;
// if we already have a tooltip for this cell, remove it.
[view removeToolTip:toolTipTag];
// get our rect.
aRect = [view frameOfCellAtColumn:column row:row];
// keep track of our tooltip so we can remove it before creating a
new 1.
toolTipTag = [view addToolTipRect:aRect owner:self userData:NULL];
}
Then, you can use the table view delegate method
-tableView:willDisplayCell:forTableColumn:row:
to convert the cell to a "ToolTipCell" and, basically, away you go.
I know this works. As a challenge to myself, I tried it. It only took a
couple minutes to write - granted, what I got working isn't very good
but that's because I didn't feel like optimizing it or working on more
general use...it "just" works.
I use your #3 method in an app I wrote back in the Public Beta days.
Now, I think I'm going to have to spend a bit more time on this and fix
up my old code.
Er, heh...replying to myself 'cause the previous post was made b4 my
4th cup of coffee...
The way I had done it before was to create the tooltip rects in the
dataSource and supply the tooltip from there as well. I was creating
all the tooltips at once and did it often. Similar to #3 but not quite.
It was bad.
What I suggested (as #4) is more like what you describe as #3 -
creating a tooltip rect for each cell. Only, it should be easy to
optimize what I described; if it's live resizing, no need to reset the
tooltips until it's done - if the cell isn't on-screen, don't bother
giving it a tooltip until it is...
That should keep you from redoing the tooltips when it isn't needed and
help keep the work-load smaller.
Hope that helps clarify. Sorry about the extra noise! :-)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.