[PyQt] doubt with QTextBrowser and QImage

Claudio A. Quezada R. claudio.quezada.r at gmail.com
Thu Nov 29 16:57:36 GMT 2007


David,

Thank you very much for your help, that is the thing i was looking for.

Very very pleased.

Best regards,

Claudio

(if you´re curious this is the project i´m working on:
http://iibsoft.googlecode.com)

Thanks again.

2007/11/27, David Boddie <dboddie at trolltech.com>:
> On Tue Nov 27 18:17:42 GMT 2007, Claudio A. Quezada wrote:
>
> > The thing is that i´d like to generate matplotlib charts (or could be
> > PyQWt) and pass them to QTextBrowser as html, but whitout having to
> > save them to disc (could be as QImage or QPixmap lists). I think this
> > maybe could be advantageous and faster (reduce hard disk writing to
> > pass them as QImage object).
>
> Perhaps. It's possibly less work to manage them if they're not on disk.
>
> > I´m stucked right now, i was checking QTextBrowser and QTextEdit
> > documentation and the only thing that maybe could do this is
> > QTextBrowser.loadResource(), but i don´t get it...
>
> Here's a way to add a resource to a text document so that any references
> to it (either using the QTextFormat API or from HTML) show an image.
>
> Let's assume you already have a document:
>
>   document = QTextDocument()
>
> And let's assume you obtained a QImage from somewhere:
>
>   image = QImage(100, 100, QImage.Format_ARGB32)
>   image.fill(qRgb(0,160,255))
>
> You register the image with the document using a certain URL:
>
>   document.addResource(QTextDocument.ImageResource,
>                        QUrl("matplotlib://image.png"), QVariant(image))
>
> Now, any references to that URL in the document should result in an image
> being displayed at that point. For example, here's how to insert a reference
> to that image using a text cursor:
>
>   imageFormat = QTextImageFormat()
>   imageFormat.setName("matplotlib://image.png")
>   cursor = QTextCursor(document)
>   cursor.insertImage(imageFormat)
>
> Or, once you have an editor, you can insert HTML to show it:
>
>   editor = QTextEdit()
>   editor.setDocument(document)
>   editor.append('<img src="matplotlib://image.png">')
>   editor.show()
>
> Hope this helps,
>
> David
> --
> David Boddie
> Lead Technical Writer, Trolltech ASA
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


-- 
Claudio Quezada Romegialli
Ingeniero Ambiental
(02)7321665 - 81466049



More information about the PyQt mailing list