[PyQt] Styling an QMdiArea widget

David Boddie david at boddie.org.uk
Sun Apr 17 18:40:44 BST 2011


On Sun Apr 17 15:36:11 BST 2011, Sarah Mount wrote:
> On Sun, Apr 17, 2011 at 15:28, Vincent Vande Vyvre
>
> <vincent.vandevyvre at swing.be> wrote:
> > You can use setBackground()
> >
> >         self.brush = QtGui.QBrush(QtGui.QPixmap("view.jpg"))
> >         self.mdi.setBackground(self.brush)
> >
> > but reimplement sizeEvent() for rescale the pixmap
>
> Thanks, tried that code and the image doesn't appear :( There's no
> traceback so it's difficult to figure out why...

If a pixmap fails to load a file, it will fail silently rather than raising
an exception. Try creating the pixmap in a separate step then inspecting it,
like this:

  pixmap = QtGui.QPixmap("view.jpg")
  print pixmap.isNull()

There are two main reasons why this may fail (returning True):

 1. view.jpg is not in the current working directory. You can specify a
    more complete path to it, or create a resource file to bundle the
    image as part of a Python module that you can simply import.

 2. JPEG support is not built-in to your version of Qt. If you can load
    other JPEGs using the widgets/imageviewer.py example supplied with
    PyQt then this probably isn't the reason why you are experiencing
    problems, though people sometimes have problems when using deployment
    tools with versions of Qt that come with plugins for decoding JPEG and
    other image formats.

David


More information about the PyQt mailing list