我正在用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_()
我做错了什么吗?
EDIT.Python 2.7和PyQt4 4.11.4 按照 @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_()
而输出的结果是: