PDA

View Full Version : PyQt5 QPixmap



ChrisOfBristol
4th April 2015, 12:15
I've just converted a small app from Python2/Qt4 to Python3/Qt5 without much difficulty. It displays .jpg images, but it no longer displays .tif images.

#! /usr/bin/python3

import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from test_ui import Ui_MainWindow

class MyWindowClass(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)

self.ui.buttonProcessOne.clicked.connect(self.push ButtonClicked)

def pushButtonClicked(self):
myPixmap = QtGui.QPixmap('image1.tif')
self.ui.label.setScaledContents(True)
self.ui.label.setPixmap(myPixmap)


if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mywindow = MyWindowClass()
mywindow.show()
sys.exit(app.exec_())

I have tried QtWidgets.QPixmap instead of QtGui.

anda_skoa
4th April 2015, 16:57
Maybe plugin for tif images did not get built or was not loaded.

Check QtGui.QImageReader.supportedImageFormats()

Cheers,
_

ChrisOfBristol
4th April 2015, 17:57
I'd tried something like that and it didn't work because I'd got something wrong. This one works, with this result:

[PyQt5.QtCore.QByteArray(b'bmp'), PyQt5.QtCore.QByteArray(b'gif'), PyQt5.QtCore.QByteArray(b'ico'), PyQt5.QtCore.QByteArray(b'jpeg'), PyQt5.QtCore.QByteArray(b'jpg'), PyQt5.QtCore.QByteArray(b'pbm'), PyQt5.QtCore.QByteArray(b'pgm'), PyQt5.QtCore.QByteArray(b'png'), PyQt5.QtCore.QByteArray(b'ppm'), PyQt5.QtCore.QByteArray(b'svg'), PyQt5.QtCore.QByteArray(b'svgz'), PyQt5.QtCore.QByteArray(b'xbm'), PyQt5.QtCore.QByteArray(b'xpm')]
Any idea what I need to do to load the right plugin?

anda_skoa
4th April 2015, 20:35
You don't have to do anything in particular, it looks like the plugin for tif is missing.

Comparing the documentation of QImageReader of Qt4 (http://doc.qt.io/qt-4.8/qimagereader.html#supportedImageFormats) and Qt5 (http://doc.qt.io/qt-5/qimagereader.html#supportedImageFormats) it seems that TIFF is no longer supported by default.

No idea why or if the plugin was moved to a addon package of sorts.

Cheers,
_

ChrisOfBristol
4th April 2015, 21:48
I have found a package in the software manager called qt5-image-formats-plugins. Installing this fixes the problem.