Workaround for Qt 5.6 bug on windows that broke exporting QPixmap to PNG

This commit is contained in:
Kovid Goyal 2017-05-12 19:50:06 +05:30
parent f2cf7eb825
commit c91e321f42
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -818,10 +818,19 @@ def choose_osx_app(window, name, title, default_dir='/Applications'):
return app
def pixmap_to_data(pixmap, format='JPEG', quality=90):
def pixmap_to_data(pixmap, format='JPEG', quality=None):
'''
Return the QPixmap pixmap as a string saved in the specified format.
'''
if quality is None:
if format.upper() == "PNG":
# For some reason on windows with Qt 5.6 using a quality of 90
# generates invalid PNG data. Many other quality values work
# but we use -1 for the default quality which is most likely to
# work
quality = -1
else:
quality = 90
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QBuffer.WriteOnly)