def convert_icon(icon, size=None, fmt='JPG'):
    if size is None:
        size = icon.availableSizes()[0]
pixmap = icon.pixmap(size)
array = QtCore.QByteArray()
buffer = QtCore.QBuffer(array)
buffer.open(QtCore.QIODevice.WriteOnly)
pixmap.save(buffer, fmt)
buffer.close()
return array.data()
Python: конвертировать QT QIcon в jpeg?