PDA

View Full Version : QToolTip



suresh
5th September 2006, 16:20
QToolTip class of qt 3.3.4 has several functions. But QToolTip class of qt 4.1.4 does not have so much functions, even no constructor is available. Is there any alternative class for QToolTip? Or how to use that class in efficient way?

Regards,
Suresh

wysota
5th September 2006, 16:23
What exactly do you want to do with it? You have a static QToolTip::showText() method. Do you need anything more?

jpn
5th September 2006, 17:17
You can construct your own custom tooltips by using a widget with Qt::ToolTip window flag set. See Tooltips Example (http://doc.trolltech.com/4.1/widgets-tooltips.html) to get to know how and when to trigger custom tooltips. You may adapt some ideas from QToolTip implementation (src/gui/widgets/qtooltip.cpp if I remember right) as well.

suresh
5th September 2006, 19:15
I will go through the example. If any problem i get back to you.

jpn
5th September 2006, 20:11
Oh, and by the way, QToolTip supports images to be embedded out of the box by using appropriate html tags. One negative point in this approach is that the image must exist as a file.

Eg. something like

widget->setToolTip("<img src=\"image.jpg\"/>");

Not sure what would you actually like to put in a tooltip, though..

wysota
6th September 2006, 11:43
One negative point in this approach is that the image must exist as a file.
No it doesn't. You can use Qt resource system here:

widget->setToolTip("<img src=':/image.jpg'/>");

jpn
6th September 2006, 13:43
I meant that a dynamically created image (which is not loaded from a file and neither does not exist as a file), for example a screenshot thumbnail, custom painting, or similar would have to be dumped to a temp file just to be able to show it in a QToolTip using html.

wysota
6th September 2006, 16:00
You can try using QTextDocument::addResource(). I'm pretty sure tooltips use QTextDocument. However it's probably not easily accessible from within the API.