简体   繁体   中英

PySide QImage produces poor quality pixelated rendering on OS X

In a PySide application I'm developing, I've come across an extremely frustrating issue that I have spent days trying to solve. I subclassed QLabel and set a QPixmap , which can be scaled to any desired width while maintaining the aspect ratio. I understand that the scaledToWidth and scaledToHeight methods are bound to slightly distort the image but the distortion was not to the magnitude I expected. I've attempted both SmoothTransformation AND FastTransformation , the latter yielding more sharp and pixelated but less blurred and ugly. I've tried every acceptable image format and they all exhibit the same horrible rendering. Below is my QLabel subclass which holds the image:

class JXImageView(QLabel):

def __init__(self, parent, window, image, select_image, identifier, scaled_width=60, x=0, y=0):
    super(JXImageView, self).__init__(parent)
    self.move(x, y)
    pxm = QPixmap().fromImage(QImage(image))
    pxm = pxm.scaledToWidth(scaled_width, Qt.SmoothTransformation)
    self.setPixmap(pxm)
    self.setFixedSize(pxm.size())

What the image looks like with SmoothTransformation :

在此处输入图片说明

Here is the original Image:

在此处输入图片说明

Try setting the graphics system to native.

from PySide import QtCore, QtGui
QtGui.QApplication.setGraphicsSystem('native')

This may improve the rendering but 'native' can be buggy on OSx. Better support is provided in Qt5 which is being included in pyside2 (under development).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM