Possible to set a tooltip for each option of a popupmenu?

I could not find whether this is possible or not, so I direct myself to the specialists here...
Thanks

 Accepted Answer

A not-too-bad workaround is to change the tooltipstring of the pop-up menu dynamically in the function callback of the pop-up menu.

4 Comments

But in order to do that, you would have to select an item. And then you would need a method of differentiating between selecting an item to see its tooltip vs selecting an item because it is what you want to use. Unfortunately popup does not set the figure SelectionType property like listbox does.
Sorry, geonod! What I did before was changing the tooltipstring on a Listbox, not a pop-up menu. On the Listbox, the effect is almost as desired. After trying on a pop-up menu, the effect is less desirable.
What version of MATLAB are you using? I am using R2007b now and its GUI doesn't support many of the eventdata that are available in the new version of MATLAB. I might need some time to try out the new version and then report back.
No problem Fangjun. I decided to set the tooltip differently. See comments below. Now the combi tooltip-axes is the challenge...

Sign in to comment.

More Answers (2)

Setting item-specific tooltips is not very difficult, using just a tiny bit of undocumented magic powder. Take a look here: http://UndocumentedMatlab.com/blog/setting-listbox-mouse-actions/
There is only one tooltip per object, and the individual options of uicontrol popupmenus are not distinct objects.
Something might be possible at the Java level; I don't know.

7 Comments

Not distinct objects indeed...
Good remark.
You _might_ be able to hack something using the ButtonDownFcn; "If the uicontrol's Enable property is set to on, the ButtonDownFcn callback executes when you click the right or left mouse button in a 5-pixel border around the uicontrol or when you click the right mouse button on the control itself."
You would combine this with getting the figure position property, and figuring out where the upper-left corner of the popup is (because it draws downward) and looking at the Extent property (which tells you how big the popup would draw if everything was rendered), and dividing the extent by the number of entries to figure out the height per entry, and comparing the current pointer displacement downward from the stable top of the list and dividing by the height per entry to figure out how many entries downward you are currently positioned at, and then change the tooltip accordingly... and hope that if the user continues to hover there that the tooltip will pop up...
I did once implement an approximation of the above once in order to provide position-dependent right-click functionality for a listbox (I think it was). Something to do with hacking the normal context-menu functionality to be able to have two different keypress behaviors for a list. I do not remember now why I didn't use figure SelectionType if it was a listbox, and it could be that in time I replaced the context-menu hack with SelectionType checking.
Wow, ty Walter for your help, but let me immediately add that I'm a newbie with regard to the Matlab GUI (first steps with GUIDE).
Specifically for now: I have a popupmenu and beside to it an icon on which on a mouseover event a tooltip is shown containing information about the option that can be made. Eventually I like that better than for my first idea (for each option a tooltip).
But, as you already might noticed, no tooltipstrings for an axes object. I bumped onto the WindowButtonMotionFcn, but I cannot get it done.
In my GUI.m:
> set(gcf, 'WindowButtonMotionFcn', @showTooltip)
Further in that GUI.m:
> function showTooltip(src, event)
> handles = guidata(src);
> point = get(handles.axes, 'currentpoint');
Then I should check whether my cursor is positioned within the area of the axis object. But is there a problem if the Units property of the axes object is set to pixels (needed for showing the image decently)?
And then, if a hit, what should I code in order to show a tooltip-like thing?
It does turn out to be possible to detect movement within the popup menu, though the use of undocumented properties (not recommended for newcomers); see the mouse movement and mouse wheel movement callbacks that can be configured via Java, described at http://undocumentedmatlab.com/blog/uicontrol-callbacks/
If you want to create an area with an icon that can present static help information, there are multiple methods. One is to create a uicontrol() of style pushbutton, set the CData property for it to the icon you want, and set the tooltip string. Set the callback for the control to be empty so it doesn't do anything if there is a click in the area.
Or you could present help information using http://www.mathworks.com/help/techdoc/ref/helpdlg.html
You can work at the figure level instead of the axes level. Or after positioning your icon within the axes, you can set() the Units property to be data, and get() its Position; store that and you can use it to compare to the axes currentpoint property (which is always in data units.)
These are nice ideas. Maybe I will use one of them, but anyway, I like to stick with my first idea, with the wbmfcn. Working at figure level is a good idea, but how do I need to code my tooltip function to show a tooltipstring?
All of the Window* functions work only at the figure level.
To program your own tooltip function using WindowButtonMotionFcn, you should have the callback start or reset a timer. As long as there is motion, the timer callback will be postponed. When the timer callback goes off, it will be because the use has stopped moving the cursor. In the timer callback, check the figure PointerLocation, and if it is in an appropriate place, use helpdlg() or a similar function to pop up the help information.
OK, thank you Walter. I try to get on with it.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!