[PyQt] images in PyQt QTextEdit widgets

Greg Smith gsmith at troublemakerstudios.com
Thu Jun 11 15:54:22 BST 2009

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
QTextBrowser object.

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
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.

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. 

For now I guess this will be my solution. I was hoping I didn't have to
do a conversion of thumbnails that already exist, but if I have to do
so, than so be it.


-----Original Message-----
From: pyqt-bounces at riverbankcomputing.com
[mailto:pyqt-bounces at riverbankcomputing.com] On Behalf Of Hans-Peter
Sent: Thursday, June 11, 2009 7:29 AM
To: pyqt at riverbankcomputing.com
Subject: Re: [PyQt] images in PyQt QTextEdit widgets

Am Donnerstag, 11. Juni 2009 schrieb Greg Smith:
> Hey everyone, I am having a bit of a problem when trying to display a
> jpg thumbnail image in a QTextEdit widget. I have a function that
> an html string that has includes the image as well as some properties
> regarding the image sequence that the thumbnail represents. Once the
> string has been created I use the setHtml() method to set the string
> the contents of the QTextEdit. When I run my tool, I get all the text
> information, but a broken image icon is displayed instead.
> The part that mystifies me is that the html string I created is based
> off of what worked in the Qt Designer when I made the ui, once I got a
> stand in to look right I simply copied the source html and used it as
> the foundation of my method.
> The image or images in question are located on our file server which
> accessed in a typical UNC fashion, OS is WinXp x64.
> The example source code that worked looked a bit like
> so:"/////bright1/shows/stu... ../myImage.jpg".  Which I tried in my
> code, but no workie. I've tried "//bright1/shows....",
> "file://///bright1/shows..",  even "/bright1/shows....", but it seams
> that no matter what I try the image won't show. So I am kind puzzled
> why I can get a picture to work in Designer, but when I try to get it
> work at runtime of my tool. It doesn't.

How about starting with trying to access your image with QFile or
Once, you get that part working, the rest will be easy.

PyQt mailing list    PyQt at riverbankcomputing.com

More information about the PyQt mailing list