Any way to enable/disable tooltips?

It seemed to me there would be, or should be, but I can’t find it. I just want to disable all tooltips for all controls, or enable them again, probably from a menu.

Haven’t tried this, but here’s something from the docs, “App.HideTooltip”

DesktopApplication — Xojo documentation

This does not disable it, just hide some that is right now visible.

To “disable” a tooltip you need to set it empty. control.ToolTip = “”

To “enable” it you need to set a content. control.ToolTip = “Mega tool”

Create something setting and disabling those values as needed.

That’s what I have found so far. If there are many tooltips, it is quite a bit of code to set them all to empty, and then back to what they are should be. You’d really have to save them, and restore them. If there were some way to enumerate them, it might be practical.

Could you just make a function that goes through all your controls and sets the tool tip to an empty string then have all your tool tips in memory or a file to put them back?

Of course, but that is a lot of code to deal with them individually, and has to get changed anytime a control is added or changed. For each project.

I will put it in as a feature request. Like window1.tooltips.enabled = False.

Add a property to each control that holds the original tooltip. Then you can iterate over all the controls in the window and ask each one to restore their tooltip.

3 Likes

You should be able to generalize this with a Dictionary and some thoughtful use of IsA (pseudocode):

dim cachedToolTips as new Dictionary

'Hide tooltips
for each currentControl in Window.Controls
    select case true
    case currentControl IsA DesktopButton
      cachedToolTips.value(currentControl)=DesktopButton(currentControl).Tooltip
      DesktopButton(currentControl).Tooltip=""
    case etc etc etc
next

'Show Tooltips
for each currentControl in Window.Controls
    select case true
    case currentControl IsA DesktopButton
      if cachedToolTips.HasValue(currentControl) then
         DesktopButton(currentControl).Tooltip= cachedToolTips.value(currentControl)
      end
    case etc etc etc
next

Either this DesktopWindow — Xojo documentation

Or you could also subclass the controls you use (this should be done by default as you never know when you will need to tweak/fix something later down the line) and add a property to store the tooltip then add a method/computed property to turn them on/off.

2 Likes

I simplified tooltips by subclassing all my controls - each one has a string property called myToolTip with the description.

The app has a public boolean called app.displayToolTips.

In the MouseEnter event for each control, I have the following code:

me.Tooltip = If(app.displayToolTips, myToolTip, "")

No dictionaries, lists, or keeping track of all the controls.

3 Likes

That might be fairly easy, and extendable. You’d also have to restore the text if tool tips were displayed?

Surely it would be more efficient to have the IDE do it though?

It would have to be built into the framework, which it currently is not.

Yes, exactly.

I suspect it might be easier to build into the framework, than to convert even one medium sized project using the methods suggested. Somewhere there is a tooltip.show method that just needs one conditional.

When you control click or right click on a subclassed property, you can select “Inspector Behaviour”

This allows you to make the myToolTips String available in the inspector, so you can set the tools tips there, rather than in code.
Screenshot 2023-03-26 at 9.44.58 AM

Then you can set your tool tip in the inspector.
myToolTips never changes - the control’s ToolTip changes when the mouse enters the control.

Ah. I did not fully understand what you were doing there. That seems a relatively elegant solution, absent an IDE facility. Also, I did not know I could customize the inspector in that way - thanks!

My dictionary solution would be easy to implement and wouldn’t require any changes to your existing controls - unlike the subclass suggestion.

True, but it does require two case statements for every control in the IDE (or at least every one you use, or might add), so a fair amount of code. But it would also be re-useable unchanged in any other project which makes it attractive. Is there a way to enquire if a control has a tooltip property? Then it could be done for all with that property rather than special casing each.

You can look at Xojo’s Introspection stuff. You’ll at least be able to find out if a control has a property named “tooltip” but I don’t know if you’d then be able to assign it.

Looks possible, but complicated. Get each control instance name, then iterate through the properties looking for tooltip, then save in dictionary and replace with null.

Yeah. There isn’t a quickie answer here. If Xojo’s class interfaces supported properties (instead of just methods), they could define a Tooltippable interface that would allow you to implement my dictionary-based solution in about 20 lines of code instead of cases for each control class. :grin: