Reputation: 360
(Sorry for poor English, my native language is not English)
I'm using Anaconda, Pycharm, Windows 10 and QtDesigner
I'm trying to set variable that contains image as icon, and I'm having an issue that is written at title
I imported Image from PIL and QtGui,QtCore, uic from PyQt4
And this is the code:
image2 = Image.open('./Images/Cache/Cache.png')
finalimage = QtGui.QIcon()
finalimage.addPixmap(QtGui.QPixmap(image2), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.FinalImage.setIcon(finalimage)
self.FinalImage.setIconSize(QtCore.QSize(1300, 342))
It will work when I use:
finalimage.addPixmap(QtGui.QPixmap('./Images/Cache/Cache.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
But I have to use variable instead of the file path...
What do I have to change to use variable as icon?
Upvotes: 1
Views: 7892
Reputation: 120598
You need to use the ImageQt
module:
from PIL.ImageQt import ImageQt
image2 = Image.open('./Images/Cache/Cache.png')
qimage = ImageQt(image2)
pixmap = QtGui.QPixmap.fromImage(qimage)
Upvotes: 2