[Qt-interest] Images in tooltips
newsletters at philippberger.de
newsletters at philippberger.de
Wed Dec 22 15:13:09 CET 2010
>
> Hello everyone,
>
> I need to display images in tooltips. But the images can't be stored as
> internal resources or on the local disk - they're dynamically computed
> and stored as QImage instances.
>
> Searching for a way to do this, I found this old thread:
> http://lists.trolltech.com/qt-interest/2007-07/thread00818-0.html
> ...suggesting to create a custom QAbstractFileEngine.
>
> Is there any other easier approach to achieve this?
>
> Thanks for any hint.
>
> Regards,
>
> --
> /- Yves Bailly - Software developper -\
> \- Sescoi R&D - http://www.sescoi.fr -/
> "The possible is done. The impossible is being done. For miracles,
> thanks to allow a little delay."
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
Hi Yves,
Easy enough using some HTML hacks :)
I wrote a small function that will convert your QImage to a QString you
can embed into a tooltip:
QString getImageAsText(const QImage AImage) {
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
AImage.save(&buffer, "PNG");
return QString("<img
src=\"data:image/png;base64,%1\">").arg(QString(buffer.data().toBase64()));
}
HTML allows for base64 encoded data in the "src" tags, look here for more
information: http://www.greywyvern.com/code/php/binary2base64
You can use it like this:
myWidget->setToolTip(QString("Text before%1Text
after").arg(getImageAsText(image)));
I tried it and it worked like a charm, hope that works for you, too ;)
Attached is the function and an example as txt file!
Cheers,
Philipp
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: code.txt
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101222/6e9db32a/attachment.txt
More information about the Qt-interest-old
mailing list