我正在使用PyQt4编写程序,该程序显示QMessageBox
以向用户发出警告。我尝试使用setIcon()
设置默认图标,但它没有显示。
我使用的是Python 2.7和PyQt4 4.11.4。
以下是一个例子:
import sys
from PyQt4.QtGui import QApplication, QMessageBox
app = QApplication(sys.argv)
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("Where is my icon?")
msg.exec_()
我做错了吗?
编辑:按照mata的要求,这是我当前的输出:
如果我在Qt之外寻找特定图像,它会按预期工作:
import sys
from PyQt4.QtGui import QApplication, QMessageBox, QPixmap, QImage
from PyQt4.QtCore import Qt
import urllib
url = 'http://www.google.com/images/srpr/logo1w.png'
data = urllib.urlopen(url).read()
app = QApplication(sys.argv)
image = QImage()
image.loadFromData(data)
pixmap = QPixmap(image).scaledToHeight(32, Qt.SmoothTransformation)
msg = QMessageBox()
msg.setIconPixmap(pixmap)
msg.setText("There is an icon from the Internet here!")
msg.exec_()
输出: