Unsolved PySide2 display only few images and show error in case high quality image
-
I am trying to display image in PySide2 but It only open few images and show this error when it failed to open image
QPixmap::scaled: Pixmap is a null pixmap
Here is complete code of the app
import sys from PySide2 import QtGui, QtCore from PySide2.QtWidgets import QFileDialog,QLabel,QAction,QMainWindow,QApplication class Window(QMainWindow): def __init__(self): super(Window, self).__init__() self.setGeometry(100, 100, 500, 300) self.setWindowTitle("PyQT Show Image") openFile = QAction("&File", self) openFile.setShortcut("Ctrl+O") openFile.setStatusTip("Open File") openFile.triggered.connect(self.file_open) self.statusBar() mainMenu = self.menuBar() fileMenu = mainMenu.addMenu('&File') fileMenu.addAction(openFile) self.lbl = QLabel(self) self.setCentralWidget(self.lbl) self.home() def home(self): self.show() def file_open(self): name = QFileDialog.getOpenFileName(self, 'Open File') #print(name) pixmap = QtGui.QPixmap(name[0]) self.lbl.setPixmap(pixmap.scaled(self.lbl.size() , QtCore.Qt.KeepAspectRatio , QtCore.Qt.SmoothTransformation)) def run(): app = QApplication(sys.argv) GUI = Window() sys.exit(app.exec_()) run()
Please help me How I can solve this I am using windows os
-
@haider said in PySide2 display only few images and show error in case high quality image:
pixmap = QtGui.QPixmap(name[0])
I don't see how we can help you. If that returns
nullptr
/None
, what would you like us to do? Find out why it did so, just as an e.g. you did not pick an acceptable file for conversion to a pixmap. -
Hi,
To add to @JonB, the user may have canceled the dialog. You should check that as well.