1

I have an application where tooltips are used to give information on each of a graphical array of objects. I subsequently want to use the content of the tooltip to create any particular object of interest. If the contents of the tooltip can be written to the paste buffer then I should be able to do this easily. But I haven't been able to figure out how to do this...

  • I'm not sure Mathematica is the best tool for this. Depending on your operation system & the application you are using, there is probably a more direct way to extract the contents of a displayed tooltip, see e.g. this discussion (unless of course your "application" is a Mathematica notebook) – Lukas Lang May 04 '21 at 13:38
  • Thanks for that, but my application is indeed a Mathematica notebook! – robertofbaycot May 04 '21 at 15:00

1 Answers1

3

Since you don't provide the code for your application, let's use this as example:

SeedRandom@1
Graphics[
 {
  AbsolutePointSize@10,
  Tooltip[Point@#, #] & /@ RandomReal[{0, 1}, {10, 2}]
  }
 ]

enter image description here

If we now want to be able to copy something to the clipboard, we can use EventHandler and CopyToClipboard

SeedRandom@1
Graphics[
 {
  AbsolutePointSize@10,
  EventHandler[
     Tooltip[Point@#, #],
     {"MouseClicked" :> CopyToClipboard@#}
     ] & /@ RandomReal[{0, 1}, {10, 2}]
  }
 ]

Now, clicking on a point puts its coordinates into the clipboard. Note that it doesn't need to be a Graphics expression, EventHandler can be used anywhere where Tooltip works.

Lukas Lang
  • 33,963
  • 1
  • 51
  • 97
  • Thanks very much for that - that looks very promising. It will take me a little while to apply it to my application. Unfortunately, my application does not lend itself to giving a brief example - I will see if I can think of something similar to illustrate it. – robertofbaycot May 05 '21 at 11:21
  • This works very well and is simple and versatile. Thank-you very much. One disappointment, which is down to Mathematica, not your Answer, is that Paste[] does not work as expected, so if you write x=Paste[], x is set to Null. This has been noted elsewhere here and here. – robertofbaycot May 06 '21 at 11:28