我目前正在做一个小的应用程序来安排音乐课,并试图添加一个背景图像。当我添加图像时,它还会重复菜单栏和工具栏中的图像。我怎么才能阻止这一切的发生?
提前感谢!
import sys
from PyQt4 import QtGui
class windowMain(QtGui.QMainWindow):
def __init__(self):
super(windowMain, self).__init__()
self.initUI()
def initUI(self):
#Layout of window
self.resize(700, 500) #Maximizing main window
self.center()
self.setWindowTitle('Lesson Planner') #Setting window title
self.setStyleSheet("border-image: url(p.jpg);")
self.show() #Showing the window发布于 2013-11-11 20:29:59
如果您不指定样式表应用于哪个小部件,它将级联到所有子部件(即,就像CSS一样)。因此,与CSS一样,您需要使用正确的选择器语法将背景图像应用于适当的小部件。
例如,一种方法是为主窗口的中心小部件设置objectName,然后在选择器中使用该名称:
def initUI(self):
self.centralWidget().setObjectName('CentralWidget')
self.setStyleSheet("""
#CentralWidget { background-image: url(./image.png) }
""")https://stackoverflow.com/questions/19894039
复制相似问题