[Qt-interest] Images in tooltips
Pritam Ghanghas
pritam_ghanghas at infosys.com
Wed Dec 29 15:37:37 CET 2010
On Wed, 2010-12-22 at 20:10 +0530, Yves Bailly wrote:
> newsletters at philippberger.de a écrit :
> >> 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.
> > [...]
> >
> > 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()));
> > }
>
> Philipp, that's simply brilliant, works great :-)
>
> Thanks a lot for this nice trick.
>
Hi,
I tried this. Didn't work for me. I am appending a small code snippet
almost same as yours. Tootip shows some blank placeholder image instead
of actual image. I have set the image onto label just to show that image
was loaded. Do you see anything wrong in it?
#include <QtGui>
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
QImage image("/usr/share/icons/Human/32x32/actions/sleep.png");
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "PNG");
QString imgStr = QString("<img src=\"data:image/png;base64,%1
\">").arg(QString(buffer.data().toBase64()));
QLabel label2;
label2.setPixmap(QPixmap::fromImage(image));
label2.resize(100,100);
label2.show();
label2.setToolTip(imgStr);
app.exec();
}
--
Thanks,
Pritam
**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
for the use of the addressee(s). If you are not the intended recipient, please
notify the sender by e-mail and delete the original message. Further, you are not
to copy, disclose, or distribute this e-mail or its contents to any other person and
any such actions are unlawful. This e-mail may contain viruses. Infosys has taken
every reasonable precaution to minimize this risk, but is not liable for any damage
you may sustain as a result of any virus in this e-mail. You should carry out your
own virus checks before opening the e-mail or attachment. Infosys reserves the
right to monitor and review the content of all messages sent to or from this e-mail
address. Messages sent to or from this e-mail address may be stored on the
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***
More information about the Qt-interest-old
mailing list