【发布时间】:2018-09-08 22:14:17
【问题描述】:
我正在尝试将图标加载到工具按钮中。我需要首先创建一个像素图,以便将其添加到 QIcon,然后将其添加到工具按钮中。但是,像素图始终为空,工具按钮上除了“...”的默认文本外没有任何显示
看看这个
file = ":/icons/refresh.jpg"
if QtCore.QFile.exists(file):
print("File exists")
else:
print("Does not exist")
pixmap = QtGui.QPixmap(file)
print(pixmap.isNull())
>>>File exists
>>>True
为什么给出有效文件时没有创建像素图?
我在 Windows 10 上使用 PyQt5 v5.5 在 virtualenv 中运行 Python 3.4
【问题讨论】:
-
您可以使用QImageReader来检查文件的有效性,还可以检测图像格式。
标签: python qt pyqt5 qtgui qpixmap