I am making a desktop application using the PySide2 implementation of Qt. Something this application needs to do is display high quality images to the user, however when I use the QPixmap class, images are always at significantly lower quality that the JPEG files they came from.
I have followed the advice of others by using the QtCore.Qt.KeepAspectRatio and QtCore.Qt.SmoothTransformation tags, which did help a little bit, however the images are still coming in low quality and any small text in images is illegible.
I am using this code to display images to the user.
pixmap = QtGui.QPixmap(os.path.join(self.imageFolder,
imageSplit[0] + '_' + str(self.currentPageNum) + '_' + '0'))
pixmap = pixmap.scaled(self.imageWidth, self.imageHeight,
QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
icon = QtGui.QIcon(pixmap)
self.imageIcon.setIcon(icon)
However as stated the image is coming in at significantly lower quality than the input JPEG. Is there any way to get higher image quality? If not, is there anything else that you would recommend me to do if I need higher quality images presented to the user?
By request, here is an example of an input image vs it's pixmap representation.
TL; DR; Upload the image to QIcon using the path.
QIcon can load the image without using the QPixmap, and when you paint it with the paint()
method it will scale it using the geometric properties of that element.
If instead you scale it using QPixmap you will be introducing more errors due to downsampling / upsampling, in addition to smoothing it also adds more errors.