Results 1 to 7 of 7

Thread: QPixmap into QTextBrowser

  1. #1
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QPixmap into QTextBrowser

    Hi.

    How can I see a QPixmap into a QTextBrowser with the <img src=""> HTML code?

    The QPixmap is loaded from a SQLite database.

    Thanks

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap into QTextBrowser

    Quote Originally Posted by xgoan View Post
    Hi.

    How can I see a QPixmap into a QTextBrowser with the <img src=""> HTML code?

    The QPixmap is loaded from a SQLite database.

    Thanks
    The QPixmap is loaded from a SQLite database.v ??? as image?

    <img src"/Fullpath/name.xxx " /> .xxx supported extension image.....


    Qt Code:
    1. void Html_Editor::MakeInsertImage()
    2. {
    3. QString subtext;
    4. QString im = QFileDialog::getOpenFileName(this,tr("Scegli una immagine"),QString(setter.value("LastDir").toString()),"Image (*.png *.jpg)");
    5. if (im.size() > 3) {
    6. subtext ="<img src='"+im+"' border='0' />";
    7. QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(subtext);
    8. html_area->textCursor().insertFragment(fragment);
    9. }
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap into QTextBrowser

    Yes I store images as BLOBs in the database, this is the problem

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap into QTextBrowser

    Maybe you can add images to the document using QTextDocument::addResource()?

  5. #5
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap into QTextBrowser

    Quote Originally Posted by jacek View Post
    Maybe you can add images to the document using QTextDocument::addResource()?

    It's possible but how it works? I can't find examples of it

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap into QTextBrowser

    Quote Originally Posted by xgoan View Post
    It's possible but how it works? I can't find examples of it
    I would try:
    Qt Code:
    1. doc->addResource( QTextDocument::ImageResource, QUrl( "image.png" ), image );
    To copy to clipboard, switch view to plain text mode 
    (assuming that you have <img src="image.png"/> tag in your document).

  7. The following user says thank you to jacek for this useful post:

    xgoan (3rd November 2006)

  8. #7
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap into QTextBrowser

    Qt Code:
    1. void WaypointItem::cambiarPrevio(){
    2. QString texto(m_texto);
    3.  
    4. texto=texto.replace("%WAYPOINT%", m_waypoint!="" ? m_waypoint : " -- VACIO -- ");
    5. texto=texto.replace("%DISTANCIA%", QString("%1 metros").arg(m_distancia));
    6. texto=texto.replace("%TIEMPO%", QString("%1 minutos").arg(m_tiempo));
    7. texto=texto.replace("%IMAGEN1%", "imagen1.png");
    8. texto=texto.replace("%IMAGEN2%", "imagen2.png");
    9. QPixmap imagen1;
    10. imagen1.loadFromData(m_imagen1);
    11. doc->addResource(QTextDocument::ImageResource, QUrl("imagen1.png"), imagen1);
    12. QPixmap imagen2;
    13. imagen2.loadFromData(m_imagen1);
    14. doc->addResource(QTextDocument::ImageResource, QUrl("imagen2.png"), imagen1);
    15.  
    16. doc->setHtml(texto);
    17. setDocument(doc);
    18. }
    To copy to clipboard, switch view to plain text mode 

    It appears to work perfect.

    Thank's

Similar Threads

  1. QPixmap -> HICON trouble.
    By krivenok in forum Qt Programming
    Replies: 1
    Last Post: 11th August 2006, 15:51
  2. Loading a custom image into a QPixmap
    By KShots in forum Qt Programming
    Replies: 12
    Last Post: 5th August 2006, 00:16
  3. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 16:24
  4. [QT4] QtextBrowser and image size (win)
    By sebgui in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 21:01
  5. how to adjust sizes of QTextBrowser?
    By Pan Wojtas in forum Qt Programming
    Replies: 2
    Last Post: 7th February 2006, 22: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.