There are two problems:
- there is a typo in the second line, as you added a
;}
at the end of the background, which makes the stylesheet invalid;
- using the "
*
" universal selector (which is almost the same as using QWidget
) means that all widgets will use the properties declared for it, and since you're probably setting the stylesheet on a QMainWindow (which inherits from QWidget), the image background is shown for both the main window and its central widget; the universal selector should be used with care, and especially avoided for top level widgets;
So, besides fixing the typo, you should apply the background only for the widget you're interested into. A good solution could be to set the object name of the central widget (if it's not already set, for instance when using a Designer file) and use the appropriate selector in the stylesheet.
I also recommend you to use better format and indentation on stylesheets, as it will makes them more readable, allowing you to find syntax errors more easily.
self.window.centralWidget().setObjectName('centralWidget')
self.window.setStyleSheet('''
QWidget#centralWidget {
color: qlineargradient(spread:pad, x1:0 y1:0, x2:1 y2:0,
stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));
background: qlineargradient(x1:0 y1:0, x2:1 y2:0,
stop:0 #ffc982, stop:1 #ff9982);
background-image: url(image.png);
background-repeat: no-repeat;
}''')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…