Possible to set a tooltip for each option of a popupmenu?
Show older comments
I could not find whether this is possible or not, so I direct myself to the specialists here...
Thanks
Accepted Answer
More Answers (2)
Yair Altman
on 10 Sep 2011
3 votes
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/
Walter Roberson
on 3 Sep 2011
1 vote
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
geomod
on 3 Sep 2011
Walter Roberson
on 3 Sep 2011
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.
geomod
on 3 Sep 2011
Walter Roberson
on 3 Sep 2011
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.)
geomod
on 4 Sep 2011
Walter Roberson
on 4 Sep 2011
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.
geomod
on 5 Sep 2011
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!