PDA

View Full Version : Accessing generated pixmaps in html / Custom tooltips



Pieter from Belgium
31st July 2009, 10:31
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

yogeshgokul
31st July 2009, 10:37
You can use

QToolTip::setPalette

nish
31st July 2009, 10:40
take a look at the tooltip of libqxt ..www.libqxt.org/ (http://www.libqxt.org/)
doc.libqxt.org/0.5.0/classQxtToolTip.html

yogeshgokul
31st July 2009, 10:46
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.



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".


Can I register an in memory image as a resource?
Try this EXMAPLE (http://pepper.troll.no/s60prereleases/doc/ipc-sharedmemory.html)

nish
31st July 2009, 10:47
abe quote to theek se kar liya kar..

yogeshgokul
31st July 2009, 10:49
abe quote to theek se kar liya kar..bhawnao ko samjho,

aamer4yu
31st July 2009, 11:22
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 :)

wagmare
31st July 2009, 11:56
or u can show ur tool tip at particular instance as

QPoint value (x , y );
QString test = "String";
QToolTip::setPalette(color);
QToolTip::setFont(serifFont);
QToolTip::showText(value2, test);

and can hide it using
QToolTip::hideText();

nish
31st July 2009, 13:05
or u can show ur tool tip at particular instance as

QPoint value (x , y );
QString test = "String";
QToolTip::setPalette(color);
QToolTip::setFont(serifFont);
QToolTip::showText(value2, test);

and can hide it using
QToolTip::hideText();

he do not want this. thats simple tooltip..

numbat
1st August 2009, 15:24
You can do this by subclassing QAbstractFileEngine. A bare-bones implementation (though probably enough) follows:

Header:


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QAbstractFileEngineHandler>
#include <QAbstractFileEngine>
#include <QDateTime>
#include <QByteArray>
#include <QtAlgorithms>

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};

class NumbatEngineHandler : public QAbstractFileEngineHandler
{
public:
QAbstractFileEngine *create(const QString &fileName) const;
};

class NumbatEngine : public QAbstractFileEngine
{
public:
NumbatEngine(const QString& fileName);
bool caseSensitive () const { return false; }
bool close () { return true; }
QStringList entryList ( QDir::Filters filters, const QStringList & filterNames ) const { return QStringList(); }
FileFlags fileFlags ( FileFlags type = FileInfoAll ) const
{ return QAbstractFileEngine::ReadOtherPerm | QAbstractFileEngine::ExeOtherPerm | QAbstractFileEngine::FileType | QAbstractFileEngine::WriteOtherPerm; }
QString fileName ( FileName file = DefaultName ) const { return m_fileName; }
QDateTime fileTime ( FileTime time ) const { return QDateTime(); }
bool mkdir ( const QString & dirName, bool createParentDirectories ) const { return false; }
QString owner ( FileOwner owner ) const { return QString(); }
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:
QByteArray* m_bytes;
QString m_fileName;
qint64 m_filePos;
};


#endif // MAINWINDOW_H


CPP File:


#include "mainwindow.h"
#include <QMap>
#include <QPixmap>
#include <QLabel>
#include <QApplication>

QAbstractFileEngine * NumbatEngineHandler::create(const QString &fileName) const
{
// We handle all files which start with ???
if (fileName.toLower().startsWith("???"))
return new NumbatEngine(fileName);
else
return 0;
}


NumbatEngine::NumbatEngine(const QString& fileName)
: QAbstractFileEngine(), m_fileName(fileName), m_filePos(0)

{
static QMap<QString, QByteArray*> map;

if (map.contains(m_fileName))
{
m_bytes = map.value(m_fileName);
}
else
{
m_bytes = new QByteArray;
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)
: QMainWindow(parent)
{
QPixmap pix("img.png");
pix.save("???Hello.png");


QLabel * lbl = new QLabel;
lbl->setText("<b> this is a test</b><img src=\"???Hello.png\" />");

setCentralWidget(lbl);
}


MainWindow::~MainWindow()
{
}

int main(int argc, char **argv)
{
QApplication app(argc, argv);

NumbatEngineHandler engine;

MainWindow window;
window.show();

return app.exec();
}