Accessing generated pixmaps in html / Custom tooltips
Hi,
In a tooltip, I would like to include an image that is to be generated at runtime. I would do this by using html for the tooltip text.
However, how can I refer to this generated pixmap in this html?
I don't like writing this image to disk.
Can I register an in memory image as a resource?
Is there a way to have custom widgets as tooltips? Of course I could try to simulate the tooltip behavior, but it would be nice to have all look and feel aspects of tooltips, yet to make full customization of its contents possible.
Thanks,
Pieter
Re: Accessing generated pixmaps in html / Custom tooltips
Re: Accessing generated pixmaps in html / Custom tooltips
take a look at the tooltip of libqxt ..www.libqxt.org/
doc.libqxt.org/0.5.0/classQxtToolTip.html
Re: Accessing generated pixmaps in html / Custom tooltips
Quote:
Originally Posted by
Pieter from Belgium
In a tooltip, I would like to include an image that is to be generated at runtime. I would do this by using html for the tooltip text.
Go ahead and give it a try.
Quote:
However, how can I refer to this generated pixmap in this html?
I don't like writing this image to disk.
I dont think so, that you can use an "image in memory" in html tags. You have to write it on disk, or use "setPalette".
Quote:
Can I register an in memory image as a resource?
Try this EXMAPLE
Re: Accessing generated pixmaps in html / Custom tooltips
abe quote to theek se kar liya kar..
Re: Accessing generated pixmaps in html / Custom tooltips
Quote:
Originally Posted by
MrDeath
abe quote to theek se kar liya kar..
bhawnao ko samjho,
Re: Accessing generated pixmaps in html / Custom tooltips
Quote:
Is there a way to have custom widgets as tooltips? Of course I could try to simulate the tooltip behavior, but it would be nice to have all look and feel aspects of tooltips, yet to make full customization of its contents possible.
Yes, there is a way.
Override the tooltip event(QEvent::ToolTip) on your main window or application.. and show your custom widget as tooltip.
You can also use a filter to catch the toopltip event . In such case you wont need to change existing code :)
Re: Accessing generated pixmaps in html / Custom tooltips
or u can show ur tool tip at particular instance as
and can hide it using
QToolTip::hideText();
Re: Accessing generated pixmaps in html / Custom tooltips
Quote:
Originally Posted by
wagmare
or u can show ur tool tip at particular instance as
and can hide it using
QToolTip::hideText();
he do not want this. thats simple tooltip..
Re: Accessing generated pixmaps in html / Custom tooltips
You can do this by subclassing QAbstractFileEngine. A bare-bones implementation (though probably enough) follows:
Header:
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QAbstractFileEngineHandler>
#include <QAbstractFileEngine>
#include <QDateTime>
#include <QByteArray>
#include <QtAlgorithms>
{
Q_OBJECT
public:
~MainWindow();
};
{
public:
};
{
public:
NumbatEngine(const QString& fileName);
bool caseSensitive () const { return false; }
bool close () { return true; }
FileFlags fileFlags ( FileFlags type = FileInfoAll ) const
QString fileName
( FileName
file = DefaultName
) const { return m_fileName;
} bool mkdir
( const QString & dirName,
bool createParentDirectories
) const { return false;
} uint ownerId ( FileOwner owner ) const { return -2; }
bool remove () { return false; }
bool rename ( const QString & newName
) { return false;
} bool rmdir
( const QString & dirName,
bool recurseParentDirectories
) const { return false;
} void setFileName
( const QString & file ) { m_fileName
= file;
} bool setPermissions ( uint perms ) { return false; }
bool setSize ( qint64 size ) { m_bytes->resize(size); return true; }
qint64 size () const { return m_bytes->size(); }
bool seek ( qint64 offset ) { m_filePos = offset; return true; }
bool open
( QIODevice::OpenMode mode
) { return true;
} bool isRelativePath () const { return false; }
qint64 write ( const char * data, qint64 len );
qint64 read ( char * data, qint64 maxlen );
private:
qint64 m_filePos;
};
#endif // MAINWINDOW_H
CPP File:
Code:
#include "mainwindow.h"
#include <QMap>
#include <QPixmap>
#include <QLabel>
#include <QApplication>
{
// We handle all files which start with ???
if (fileName.toLower().startsWith("???"))
return new NumbatEngine(fileName);
else
return 0;
}
NumbatEngine::NumbatEngine(const QString& fileName)
{
if (map.contains(m_fileName))
{
m_bytes = map.value(m_fileName);
}
else
{
map[m_fileName] = m_bytes;
}
}
qint64 NumbatEngine::write ( const char * data, qint64 len )
{
if (m_filePos + len > m_bytes->size()) m_bytes->resize(m_filePos + len);
qCopy(data, data + len, m_bytes->data() + m_filePos);
m_filePos += len;
return len;
}
qint64 NumbatEngine::read ( char * data, qint64 maxlen )
{
qint64 readBytes;
if (m_filePos + maxlen > m_bytes->size())
readBytes = m_bytes->size() - m_filePos;
else
readBytes = maxlen;
qCopy(m_bytes->constData() + m_filePos,
m_bytes->constData() + m_filePos + readBytes, data);
m_filePos += readBytes;
return readBytes;
}
/* Demonstration. */
MainWindow
::MainWindow(QWidget *parent
){
pix.save("???Hello.png");
lbl->setText("<b> this is a test</b><img src=\"???Hello.png\" />");
setCentralWidget(lbl);
}
MainWindow::~MainWindow()
{
}
int main(int argc, char **argv)
{
NumbatEngineHandler engine;
MainWindow window;
window.show();
return app.exec();
}