PDA

View Full Version : QPixmap into QTextBrowser



xgoan
25th October 2006, 14:02
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

patrik08
25th October 2006, 14:10
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.....




void Html_Editor::MakeInsertImage()
{
QString subtext;
QString im = QFileDialog::getOpenFileName(this,tr("Scegli una immagine"),QString(setter.value("LastDir").toString()),"Image (*.png *.jpg)");
if (im.size() > 3) {
subtext ="<img src='"+im+"' border='0' />";
QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(subtext);
html_area->textCursor().insertFragment(fragment);
}

}

xgoan
25th October 2006, 15:23
Yes I store images as BLOBs in the database, this is the problem

jacek
25th October 2006, 16:52
Maybe you can add images to the document using QTextDocument::addResource()?

xgoan
3rd November 2006, 13:07
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 :confused:

jacek
3rd November 2006, 13:38
It's possible but how it works? I can't find examples of it :confused:
I would try:
doc->addResource( QTextDocument::ImageResource, QUrl( "image.png" ), image );(assuming that you have <img src="image.png"/> tag in your document).

xgoan
3rd November 2006, 14:05
void WaypointItem::cambiarPrevio(){
QString texto(m_texto);
QTextDocument *doc=new QTextDocument;

texto=texto.replace("%WAYPOINT%", m_waypoint!="" ? m_waypoint : " -- VACIO -- ");
texto=texto.replace("%DISTANCIA%", QString("%1 metros").arg(m_distancia));
texto=texto.replace("%TIEMPO%", QString("%1 minutos").arg(m_tiempo));
texto=texto.replace("%IMAGEN1%", "imagen1.png");
texto=texto.replace("%IMAGEN2%", "imagen2.png");
QPixmap imagen1;
imagen1.loadFromData(m_imagen1);
doc->addResource(QTextDocument::ImageResource, QUrl("imagen1.png"), imagen1);
QPixmap imagen2;
imagen2.loadFromData(m_imagen1);
doc->addResource(QTextDocument::ImageResource, QUrl("imagen2.png"), imagen1);

doc->setHtml(texto);
setDocument(doc);
}

It appears to work perfect.

Thank's :D