Search code examples
qttooltip

How to show Tooltips in Qt


I'm writing a program using Qt4.5 that shows a book in another language. So I have a large body of text and I want to display a different tooltip for each word (the tooltip will contain parsing information for the appropriate word).

What is the best way of doing this?

I have a working solution for a browser using php and jquery so I had considered porting it somehow to c++ and displaying it using QWebView but I have a feeling that there's a better solution out there...

[edit] Let me add that I display the words out of a database so I have a database that looks like this:

| Id | Word | ParsingInfo                  |
--------------------------------------------
|  0 | The  | Article                      |
|  1 | fish | Noun, Subject etc.           |
|  2 | are  | Verb, 3rd Person Singular... |
|  3 | blue | Adjective...                 |

So I need some way of figuring out what the id is of the word being displayed, not merely the word because, for example, the word "that" can be used in different ways or "wind" has a homograph (the language I am working with is greek though).


Solution

  • If you only use simple HTML, you can switch to a QTextBrowser. Then use the cursorForPosition method to get a QTextCursor from which you can get the text at the current location.