Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, July 2007
[QT4] Porting custom tooltips with images from Qt3


Message 1 in thread

My application needs to create images on the fly and use those images as
tooltips.  My QT3 application does this by registering the image with
QMimeSourceFactory and then using an img tag in the tooltip text.  I
then ported this to QT4 using the Q3MimeSourceFactory support class:

Q3MimeSourceFactory::defaultFactory()->setImage("MyTipImage", image);
QToolTip::showText(pos, "<p>Image Caption</p><img src=\"MyTipImage\">");

This occurs every time the tip is displayed and has 2 problems:
- It use the support classes and I would like to remove these from my
code
- The images appear to cache within the widget.  I need the tip image to
change as I move though the widget.  The image does not change until my
mouse leaves and re-enters the widget.  This did not happen in QT3.

I have looked at the QT4 docs and found no easy solution.  Since these
are tooltips, I don't believe I can access a QTextDocument on which to
call addResource.  Also, QResource::registerResource requires the data
to be in RCC binary format and I don't know how to make that from my
dynamic image.  So, short if poping up my own tooltip widget and trying
to get it to behave the same as a normal tooltip, is there any way to
include my dynamic images with QT4 and without the QT3 support classes?

Thanks
Rob


Message 2 in thread

Bachrach, Robert L schrieb:
> My application needs to create images on the fly and use those images as
> tooltips.  My QT3 application does this by registering the image with
> QMimeSourceFactory and then using an img tag in the tooltip text.  I
> then ported this to QT4 using the Q3MimeSourceFactory support class:
> 
> Q3MimeSourceFactory::defaultFactory()->setImage("MyTipImage", image);
> QToolTip::showText(pos, "<p>Image Caption</p><img src=\"MyTipImage\">");
> 
> This occurs every time the tip is displayed and has 2 problems:
> - It use the support classes and I would like to remove these from my code
> - The images appear to cache within the widget.  I need the tip image to
> change as I move though the widget.  The image does not change until my
> mouse leaves and re-enters the widget.  This did not happen in QT3.
> 
> I have looked at the QT4 docs and found no easy solution.  Since these
> are tooltips, I don't believe I can access a QTextDocument on which to
> call addResource.  Also, QResource::registerResource requires the data
> to be in RCC binary format and I don't know how to make that from my
> dynamic image.  So, short if poping up my own tooltip widget and trying
> to get it to behave the same as a normal tooltip, is there any way to
> include my dynamic images with QT4 and without the QT3 support classes?

What I have done sometimes ago was:

I've created a class which is derivated from QAbstractFileEngine which
handled 'image:file.png' for example. This file can set as link in the
ToolTip-Text. And the file.png can be created on demand.

Stefan

--
 [ signature omitted ]