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
def __init__(self, parent=None):
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.buttonProcessOne.clicked.connect(self.pushButtonClicked)
def pushButtonClicked(self):
myPixmap
= QtGui.
QPixmap('image1.tif') self.ui.label.setScaledContents(True)
self.ui.label.setPixmap(myPixmap)
if __name__ == "__main__":
mywindow = MyWindowClass()
mywindow.show()
sys.exit(app.exec_())
#! /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.pushButtonClicked)
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_())
To copy to clipboard, switch view to plain text mode
I have tried QtWidgets.QPixmap instead of QtGui.
Bookmarks