[PyQt] doubt with QTextBrowser and QImage
Claudio A. Quezada R.
claudio.quezada.r at gmail.com
Thu Nov 29 16:57:36 GMT 2007
Thank you very much for your help, that is the thing i was looking for.
Very very pleased.
(if you´re curious this is the project i´m working on:
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)
> You register the image with the document using a certain URL:
> 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()
> cursor = QTextCursor(document)
> Or, once you have an editor, you can insert HTML to show it:
> editor = QTextEdit()
> editor.append('<img src="matplotlib://image.png">')
> Hope this helps,
> David Boddie
> Lead Technical Writer, Trolltech ASA
> PyQt mailing list PyQt at riverbankcomputing.com
Claudio Quezada Romegialli
(02)7321665 - 81466049
More information about the PyQt