On Sun, Apr 17, 2011 at 16:48, Vincent Vande Vyvre <vincent.vandevy...@swing.be> wrote: > Le 17/04/11 16:36, Sarah Mount a écrit : > > On Sun, Apr 17, 2011 at 15:28, Vincent Vande Vyvre > <vincent.vandevy...@swing.be> wrote: > > Le 17/04/11 15:17, Sarah Mount a écrit : > > Hi everyone, > > I have a main application window that I want to style with a style > sheet like this: > > > #mywidget { > background : white; > background-image : url(:/images/images/EfDChancoComposite.jpg); > background-repeat : no-repeat; > } > > > When the project is created, the widget that I want to apply the CSS > to becomes an MDI area, so presumably the styling now needs to apply > to the MDI area, not the original widget, like this: > > > class MyMainWindow(QtGui.QMainWindow, Ui_MainWindow): > def __init__(self, parent=None): > QtGui.QMainWindow.__init__(self) > self.setupUi(self) > self.mdi = QtGui.QMdiArea() > self.mdi.setStyleSheet("QMdiArea { background : white; > background-image : url(:/images/images/EfDChancoComposite.jpg); > background-repeat : no-repeat; }") > self.setCentralWidget(self.mdi) > > > ...but that doesn't work! Is this because QMdiArea widgets can't be > styled with CSS, and if so, is it possible to use a QBrush to do this > (including the no-repeat directive)? Or, have I just misunderstood the > API? > > > Many thanks, > > Sarah > > Hi, > > 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... > > Sarah > > Strange, if I use this code that works: > > class MyMainWindow(QtGui.QMainWindow): > def __init__(self, parent=None): > QtGui.QMainWindow.__init__(self) > self.mdi = QtGui.QMdiArea() > self.setCentralWidget(self.mdi) > pix = QtGui.QPixmap("img.jpg") > self.brush = QtGui.QBrush(pix) > self.mdi.setBackground(self.brush) >
Thanks, you and David were both right, the error was an incorrect path for the JPG. However, what I was after was to have one image appear in the background, and not to have the image tiled. This is possible using a style sheet, but I'm not sure a) if it's possible using a brush (your code comes out with the image tiled) or b) whether it's possible to use a style sheet, as my code for that didn't work! Any advice greatly appreciated. Sarah -- Sarah Mount, Senior Lecturer, University of Wolverhampton website: http://www.snim2.org/ twitter: @snim2 _______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt