我使用pyqt4编写了以下python程序。这是一个在窗口中显示图标的简单程序。
from PyQt4.QtGui import *
from PyQt4 import QtGui, QtCore
import sys
class Main(QtGui.QMainWindow):
def __init__(self, parent = None):
super(Main, self).__init__(parent)
self.centralWidget=QWidget()
self.setCentralWidget(self.centralWidget)
w=QGridLayout()
size=128
icon=QIcon()
mode=QIcon.Selected
state=QIcon.Off
pixma = QPixmap('a.png')
icon.addPixmap(pixma,mode,state)
label=QLabel()
label.setPixmap(icon.pixmap(size,mode,state))
w.addWidget(label,0,0,0,1)
self.centralWidget.setLayout(w)
self.resize(self.minimumSizeHint())
虽然模式设置为选中但我看不到要选择的图标。 当我以下列方式编写代码时,它会显示一个选定的图标:
from PyQt4.QtGui import *
from PyQt4 import QtGui, QtCore
import sys
class Main(QtGui.QMainWindow):
def __init__(self, parent = None):
super(Main, self).__init__(parent)
self.centralWidget=QWidget()
self.setCentralWidget(self.centralWidget)
w=QGridLayout()
size=128
icon=QIcon()
mode=QIcon.Selected
state=QIcon.Off
pixma = QPixmap('a.png')
icon.addPixmap(pixma,mode,state)
label=QLabel()
#CHANGED CODE
label.setPixmap(icon.pixmap(size,QIcon.Selected,state))
w.addWidget(label,0,0,0,1)
self.centralWidget.setLayout(w)
self.resize(self.minimumSizeHint())
可能是什么问题?