我试图将背景图像设置为我在QMainWindows中调用的这样一个QMainWindows:
class MainWin(QtGui.QMainWindow):
def __init__(self):
super(MainWin, self).__init__()
self.initUI()
def initUI(self):
#central widget
self.theboard = Board(self)
self.setCentralWidget(self.theboard)
class Board(QtGui.QFrame):
def __init__(self, parent):
super(Board, self).__init__(parent)
self.initBoard()
def initBoard(self):
#Set background Image
frame = Board
palette = QPalette()
palette.setBrush(QPalette.Background,QBrush(QPixmap("ImageTest.jpg")))
frame.setPalette(palette)就像我在网上的一些例子中发现的那样,使用Qpalette /Q像素地图。但这不管用:
self.palette = QPalette() NameError:未定义全局名称“QPalette”
为什么?在这里,我的班级:班级委员会(QtGui.QFrame):
我很好地继承了QtGui,所以Qpalette应该能工作。我不得不承认,我有点困惑于调色板的工作方式。
任何能得到的帮助,
谢谢!
发布于 2014-09-30 22:33:38
您没有在代码中编写它,所以您的问题可能是没有导入它。
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QPalette如果不是这样的话,试试如下:
palette = QPalette()
palette.setBrush(QPalette.Background,QBrush(QPixmap("anne.jpg"))) # Haha, aren't I so funny??
frame.setPalette(palette)https://stackoverflow.com/questions/26130036
复制相似问题