[PyQt] images in PyQt QTextEdit widgets

David Boddie dboddie at trolltech.com
Thu Jun 11 16:48:54 BST 2009


On Thu Jun 11 15:54:22 BST 2009, Greg Smith wrote:

> I've been trying to find examples or reference on how to take a QImage
> object and embed the results into the rich text source of my QTextEdit
> or QTextBrowser object.

Take a look at this message from earlier in the archives:

http://www.riverbankcomputing.com/pipermail/pyqt/2007-November/017851.html

> The only example I found in the Rapid Gui book regarding embedded images
> in the html rich text was an example of a image located in a resource
> file:
> "<img=':/logo.png'>"
> However I don't want to use a resource file because the thumbnail image
> changes based on user's selection and new images are constantly being
> added to a pool of thousands of thumbnails we already have.

It should be possible to browse a directory containing images files.

> I did figure out how to get it to work, and that was to use a .png file
> as opposed to a .jpg, which mystifies me to no extent. I thought that
> PyQt could read jpg just as easily as png files, but I guess not.

It can, but the JPEG decoder may have been built as a plugin, and perhaps
your application isn't finding it.

One thing to try is to enter the following lines in an interactive Python
session and see which formats are supported:

  from PyQt4.QtGui import *
  app = QApplication([])
  QImageReader.supportedImageFormats()

If your development environment is different to your deployment environment,
you will want to check that you get the same list in both places.

If you are deploying your application to other machines, you may need to
be aware of the qt.conf file:

http://www.riverbankcomputing.com/pipermail/pyqt/2008-October/020795.html

David


More information about the PyQt mailing list