Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PySide2 display only few images and show error in case high quality image
Forum Update on Monday, May 27th 2025

PySide2 display only few images and show error in case high quality image

Scheduled Pinned Locked Moved Unsolved Qt for Python
pyside2
3 Posts 4 Posters 414 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    haider
    wrote on last edited by
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • H haider

      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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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.

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        To add to @JonB, the user may have canceled the dialog. You should check that as well.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved