[PyQt] QGraphicsView to display a png

Dave Fancella dave at davefancella.com
Tue Jul 24 00:20:10 BST 2007


On Monday 23 July 2007 5:55 pm, kib2 wrote:
> Now, Dave just told me it was a bad idea to put an image on a
> QGraphicsView. I've already done it inside a Label, but I've no controls
> on it. He suggested I've to write my own widget (from Qlabel or QWidget)
> for that, but I don't see why it's a bad design decision.

Heh, I didn't mean that, I meant it's a bad design decision to use a 
QGraphicsView for the purpose of displaying a png.  QGraphicsView is 
optimized for complex 2D graphics displays and designed for that.  Think of 
things like video games (although there's certainly a lot more).  So it 
manages scrollbars (which will screw up a layout without some hacks to make 
it not use scrollbars), and otherwise exists as a window to the world you've 
created within the scene and hooks itself into your layout.  The actual 
graphics inside are completely unaware of the layout or their own context 
within your user interface, they only know themselves within the scene.  If 
you want to display a single graphic, QGraphicsView is the really wrong 
choice for that.

I don't know what the easiest choice is, either, because I just use 
QLabel.  :)  But it can't be that hard to subclass QWidget and in the 
paintevent just paint from a QPixmap.  I do consider it something of a 
weakness that there isn't a convenience class for displaying a simple graphic 
that's layout aware, and using QLabel for the purpose feels like a hack to 
me, but neither have I bothered with something else.  :)

Dave

> David : thanks again for your good work on the wiki.
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list