[PyQt] Best way to implement an Image Viewer?

TP wingusr at gmail.com
Tue Mar 9 14:07:23 GMT 2010


I'm using Windows XP, Python 2.6.4, and PyQt 4.7.1.

While trying out the example
C:\Python26\Lib\site-packages\PyQt4\examples\widgets\imageviewer.pyw,
I notice that the more I zoom into an 1553x2653 B&W PNG image, the
longer it takes to display. This becomes unacceptably long (on the
order of a few seconds) at the not so high 3x zoom factor.

Intuitively, I would have thought it would be *faster* since the more
I zoom in the fewer image pixels need to be displayed. I think what's
happening is the entire QLabel widget is getting enlarged then
cropped, rather than just displaying a sub-portion of the image:

    def scaleImage(self, factor):
        self.scaleFactor *= factor
        self.imageLabel.resize(self.scaleFactor *
self.imageLabel.pixmap().size())

I want to create an app to help people explore various image
processing operations. Fast & flexible image display is essential.

Some features I like to have:

* Zoom In/Out quickly. I can see zooming *out* being slower since more
  image pixels would be involved. Once past the 1x zoom-in factor, I'd
  rather have the pixels as raw as possible to avoid blurring edges
  like the Image Viewer example currently does.

* Compare transformations by having multiple views of images that are
  synchronized as to pan position and zoom factor. Dragging the mouse
  in any of the views should pan all the views.

* Multi-screen support.

I started off by modifying the PyQt4 Image Viewer example, but now I'm
having second thoughts. Should I really be basing my Image Viewer on a
QLabel?

Should I instead be using a QGraphicsView (even though I'll probably
only have a single image, not lots of 2D objects)?

Maybe I should use a QGLWidget (I'd rather not).

Or perhaps I have to write my own custom widget and draw using a
QPainter object?

Any tips or pointers to other PyQt-based Image Viewers would be
appreciated.


More information about the PyQt mailing list