Why are datatips editable?

I created a custom datatip using a DataTipTemplate for a plot line, but when I click on the datatip I can edit the string and change it for future datatips.
I can't find any "Editable" property for the datatip.
Is there a way to stop people editing the datatip text?
  • Please don't reply with an AI generated answer that hasn't been checked. I can do that if I wanted to. I posted here to get advice from people who have used this feature before and know what they are talking about.

 Accepted Answer

Adam Danz
Adam Danz on 19 Jun 2023
Edited: Adam Danz on 19 Jun 2023
> Is there a way to stop people editing the datatip text?
There is no way to turn off the option for users to manually edit the datatip.
If you're using the datatip function to add a datatip, you could set the DataTip object's HitTest to off to prevent all interactions with the datatip including accessing the right-click context menu and toggling the datatip off ⚠️.
d = datatip(h,x,y);
d.HitTest = 'off';

3 Comments

Thanks @Adam Danz
That does prevent the datatip from being edited. but it also stops the datatip from being removed.
Previously clicking a point would display the datatip and clicking it again would remove it. Now they just accumulate. Is there other code I need to remove datatips?
Regards
Adrian
Yes, I mentioned this in my answer 🙂. The HitTest workaround is not ideal.
You can remove all datatips in figure fig programmatically using
delete(findobj(fig,'type','DataTip'))
@Adam Danz Yes I did see that caveat in your answer (after I posted my reply).
I've raised the issue with Matlab support, maybe an editable property could be added to datatips in future. Seems strange to allow all kinds of controls on the right click and editing with the left click by default with no way to turn them off.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2022b

Tags

Asked:

on 14 Jun 2023

Commented:

on 20 Jun 2023

Community Treasure Hunt

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

Start Hunting!