Results 1 to 10 of 10

Thread: Accessing generated pixmaps in html / Custom tooltips

  1. #1
    Join Date
    Jan 2006
    Location
    Genk, Belgium
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question 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

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Accessing generated pixmaps in html / Custom tooltips

    You can use
    Qt Code:
    1. QToolTip::setPalette
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Accessing generated pixmaps in html / Custom tooltips

    Quote Originally Posted by Pieter from Belgium View Post
    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

  5. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Accessing generated pixmaps in html / Custom tooltips

    abe quote to theek se kar liya kar..

  6. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Accessing generated pixmaps in html / Custom tooltips

    Quote Originally Posted by MrDeath View Post
    abe quote to theek se kar liya kar..
    bhawnao ko samjho,

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Accessing generated pixmaps in html / Custom tooltips

    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

  8. #8
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Accessing generated pixmaps in html / Custom tooltips

    or u can show ur tool tip at particular instance as
    Qt Code:
    1. QPoint value (x , y );
    2. QString test = "String";
    3. QToolTip::setPalette(color);
    4. QToolTip::setFont(serifFont);
    5. QToolTip::showText(value2, test);
    To copy to clipboard, switch view to plain text mode 

    and can hide it using
    QToolTip::hideText();
    "Behind every great fortune lies a crime" - Balzac

  9. #9
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Accessing generated pixmaps in html / Custom tooltips

    Quote Originally Posted by wagmare View Post
    or u can show ur tool tip at particular instance as
    Qt Code:
    1. QPoint value (x , y );
    2. QString test = "String";
    3. QToolTip::setPalette(color);
    4. QToolTip::setFont(serifFont);
    5. QToolTip::showText(value2, test);
    To copy to clipboard, switch view to plain text mode 

    and can hide it using
    QToolTip::hideText();
    he do not want this. thats simple tooltip..

  10. #10
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Accessing generated pixmaps in html / Custom tooltips

    You can do this by subclassing QAbstractFileEngine. A bare-bones implementation (though probably enough) follows:

    Header:
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include <QAbstractFileEngineHandler>
    6. #include <QAbstractFileEngine>
    7. #include <QDateTime>
    8. #include <QByteArray>
    9. #include <QtAlgorithms>
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18. };
    19.  
    20. class NumbatEngineHandler : public QAbstractFileEngineHandler
    21. {
    22. public:
    23. QAbstractFileEngine *create(const QString &fileName) const;
    24. };
    25.  
    26. class NumbatEngine : public QAbstractFileEngine
    27. {
    28. public:
    29. NumbatEngine(const QString& fileName);
    30. bool caseSensitive () const { return false; }
    31. bool close () { return true; }
    32. QStringList entryList ( QDir::Filters filters, const QStringList & filterNames ) const { return QStringList(); }
    33. FileFlags fileFlags ( FileFlags type = FileInfoAll ) const
    34. { return QAbstractFileEngine::ReadOtherPerm | QAbstractFileEngine::ExeOtherPerm | QAbstractFileEngine::FileType | QAbstractFileEngine::WriteOtherPerm; }
    35. QString fileName ( FileName file = DefaultName ) const { return m_fileName; }
    36. QDateTime fileTime ( FileTime time ) const { return QDateTime(); }
    37. bool mkdir ( const QString & dirName, bool createParentDirectories ) const { return false; }
    38. QString owner ( FileOwner owner ) const { return QString(); }
    39. uint ownerId ( FileOwner owner ) const { return -2; }
    40. bool remove () { return false; }
    41. bool rename ( const QString & newName ) { return false; }
    42. bool rmdir ( const QString & dirName, bool recurseParentDirectories ) const { return false; }
    43. void setFileName ( const QString & file ) { m_fileName = file; }
    44. bool setPermissions ( uint perms ) { return false; }
    45. bool setSize ( qint64 size ) { m_bytes->resize(size); return true; }
    46. qint64 size () const { return m_bytes->size(); }
    47. bool seek ( qint64 offset ) { m_filePos = offset; return true; }
    48. bool open ( QIODevice::OpenMode mode ) { return true; }
    49. bool isRelativePath () const { return false; }
    50. qint64 write ( const char * data, qint64 len );
    51. qint64 read ( char * data, qint64 maxlen );
    52.  
    53. private:
    54. QByteArray* m_bytes;
    55. QString m_fileName;
    56. qint64 m_filePos;
    57. };
    58.  
    59.  
    60. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    CPP File:
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QMap>
    3. #include <QPixmap>
    4. #include <QLabel>
    5. #include <QApplication>
    6.  
    7. QAbstractFileEngine * NumbatEngineHandler::create(const QString &fileName) const
    8. {
    9. // We handle all files which start with ???
    10. if (fileName.toLower().startsWith("???"))
    11. return new NumbatEngine(fileName);
    12. else
    13. return 0;
    14. }
    15.  
    16.  
    17. NumbatEngine::NumbatEngine(const QString& fileName)
    18. : QAbstractFileEngine(), m_fileName(fileName), m_filePos(0)
    19.  
    20. {
    21. static QMap<QString, QByteArray*> map;
    22.  
    23. if (map.contains(m_fileName))
    24. {
    25. m_bytes = map.value(m_fileName);
    26. }
    27. else
    28. {
    29. m_bytes = new QByteArray;
    30. map[m_fileName] = m_bytes;
    31. }
    32. }
    33.  
    34. qint64 NumbatEngine::write ( const char * data, qint64 len )
    35. {
    36. if (m_filePos + len > m_bytes->size()) m_bytes->resize(m_filePos + len);
    37.  
    38. qCopy(data, data + len, m_bytes->data() + m_filePos);
    39.  
    40. m_filePos += len;
    41.  
    42. return len;
    43. }
    44.  
    45. qint64 NumbatEngine::read ( char * data, qint64 maxlen )
    46. {
    47. qint64 readBytes;
    48.  
    49. if (m_filePos + maxlen > m_bytes->size())
    50. readBytes = m_bytes->size() - m_filePos;
    51. else
    52. readBytes = maxlen;
    53.  
    54. qCopy(m_bytes->constData() + m_filePos,
    55. m_bytes->constData() + m_filePos + readBytes, data);
    56.  
    57. m_filePos += readBytes;
    58.  
    59. return readBytes;
    60. }
    61.  
    62.  
    63.  
    64. /* Demonstration. */
    65. MainWindow::MainWindow(QWidget *parent)
    66. : QMainWindow(parent)
    67. {
    68. QPixmap pix("img.png");
    69. pix.save("???Hello.png");
    70.  
    71.  
    72. QLabel * lbl = new QLabel;
    73. lbl->setText("<b> this is a test</b><img src=\"???Hello.png\" />");
    74.  
    75. setCentralWidget(lbl);
    76. }
    77.  
    78.  
    79. MainWindow::~MainWindow()
    80. {
    81. }
    82.  
    83. int main(int argc, char **argv)
    84. {
    85. QApplication app(argc, argv);
    86.  
    87. NumbatEngineHandler engine;
    88.  
    89. MainWindow window;
    90. window.show();
    91.  
    92. return app.exec();
    93. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. add custom HTML attribute by javascript in QtWebKit
    By sand.fj.wen in forum Qt Programming
    Replies: 3
    Last Post: 17th April 2009, 07:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.