I'm trying to load this .tiff image into my gui interface using PyQt's QPixmap. I have the following code:
fileName = QFileDialog.getOpenFileName(self.parent, "Open Image", "/", "Image Files (*.png *.jpg *.bmp *.tiff)");
img = QtGui.QPixmap(fileName)
scaled_img = img.scaled(self.ui.img_label.size(), QtCore.Qt.KeepAspectRatio)
self.ui.img_label.setPixmap(scaled_img)
Where img_label is a Qlabel in my GUI. I tested it with various .jpg, .png and .tiff images. It seems to be working, but when I test it on this image, it returns Null
QImageReader.supportedImageFormats and it shows that .tiff is supportedimage/tiffCan someone suggest what I might be doing wrong?
Okay, this is a bit strange. The image loads when I change the line:
img = QtGui.QPixmap(fileName)
To:
img = QtGui.QPixmap(fileName, "1")
In fact it seems to work when I specify any numeric string for the second argument. I'm not sure the second argument is supposed to be as the documentation is a bit vague about it. I hope someone can explain what's happening, as this is really puzzling me.
QFileDialog.getOpenFileName() returns a tuple. try this instead:
fileName = QFileDialog.getOpenFileName(self.parent, "Open Image", "/", "Image Files (*.png *.jpg *.bmp *.tiff)");
img = QtGui.QPixmap(fileName[0])
scaled_img = img.scaled(self.ui.img_label.size(), QtCore.Qt.KeepAspectRatio)
self.ui.img_label.setPixmap(scaled_img)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With