Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PYQT does not display the img feedback: Could not create pixmap from
Forum Updated to NodeBB v4.3 + New Features

PYQT does not display the img feedback: Could not create pixmap from

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 10.1k 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.
  • C Offline
    C Offline
    CHHC
    wrote on last edited by CHHC
    #1

    here`s my problem: when I run the program, img does not display at all. But, the form works fine in QTdesigner with displayable img. it happened in every scenario where I try to display a img whether for a Qlebal or Qpushbutton and so on.
    Down below is the code representing the issue, VSC or CMD both feedback the same problem.

    Could not create pixmap from :\1\1.jpg

    and here`s the whole test code project
    the link here: https://drive.google.com/drive/folders/1LR0y0TZ6wlEXbrBl4SZGjCzjqMXa0M6n?usp=sharing

    import sys
    from PyQt5.QtWidgets import QApplication, QMainWindow
    from PyQt5.uic import loadUi
    
    class main(QMainWindow):
        def __init__(self):
            super(main, self).__init__()
            login = loadUi('untitled.ui', self)
            login.show()
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        main = main()   
        sys.exit(app.exec_())
    
    
    

    b56d90f4-67b8-4d04-83ed-41602b9f9d84-image.png
    after the solution by using import
    cc68f3f6-3075-49bc-80f0-53273c1aa5df-image.png

    JonBJ 1 Reply Last reply
    0
    • C CHHC

      here`s my problem: when I run the program, img does not display at all. But, the form works fine in QTdesigner with displayable img. it happened in every scenario where I try to display a img whether for a Qlebal or Qpushbutton and so on.
      Down below is the code representing the issue, VSC or CMD both feedback the same problem.

      Could not create pixmap from :\1\1.jpg

      and here`s the whole test code project
      the link here: https://drive.google.com/drive/folders/1LR0y0TZ6wlEXbrBl4SZGjCzjqMXa0M6n?usp=sharing

      import sys
      from PyQt5.QtWidgets import QApplication, QMainWindow
      from PyQt5.uic import loadUi
      
      class main(QMainWindow):
          def __init__(self):
              super(main, self).__init__()
              login = loadUi('untitled.ui', self)
              login.show()
      
      if __name__ == '__main__':
          app = QApplication(sys.argv)
          main = main()   
          sys.exit(app.exec_())
      
      
      

      b56d90f4-67b8-4d04-83ed-41602b9f9d84-image.png
      after the solution by using import
      cc68f3f6-3075-49bc-80f0-53273c1aa5df-image.png

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

      @CHHC
      Hello and welcome.

      You might want to think about the title of your topics for the future. There is nothing more urgent about your question that anyone else's, and it does not need six exclamation marks :)

      Could not create pixmap from :\1\1.jpg

      :\1\1.jpg may not be the right path to the file in the Qt resources, so verify that. Otherwise, you need to read up how to access Qt resources from a Python script, because normally they are located inside the executable generated from a C++ program which does not apply in Python. See the discussion from https://forum.qt.io/topic/132695/qmake/5 onward.

      C 1 Reply Last reply
      2
      • JonBJ JonB

        @CHHC
        Hello and welcome.

        You might want to think about the title of your topics for the future. There is nothing more urgent about your question that anyone else's, and it does not need six exclamation marks :)

        Could not create pixmap from :\1\1.jpg

        :\1\1.jpg may not be the right path to the file in the Qt resources, so verify that. Otherwise, you need to read up how to access Qt resources from a Python script, because normally they are located inside the executable generated from a C++ program which does not apply in Python. See the discussion from https://forum.qt.io/topic/132695/qmake/5 onward.

        C Offline
        C Offline
        CHHC
        wrote on last edited by
        #3

        @JonB Does this mean that I have to replace all the LoadUI methods? instead of simply using the .UI files???
        That is unbelievable work for my current project. In fact, this issue wasn't there when the first time run this code.
        After I DON`T KNOW WHAT process, the img would not display properly. Of course, this issue happened in all my Qform and Qwidget.
        I just simply can figure out the solution, could you give me some advice directly? like how am I supposed to change the path or give a test on your environment?

        JonBJ 1 Reply Last reply
        0
        • C CHHC

          @JonB Does this mean that I have to replace all the LoadUI methods? instead of simply using the .UI files???
          That is unbelievable work for my current project. In fact, this issue wasn't there when the first time run this code.
          After I DON`T KNOW WHAT process, the img would not display properly. Of course, this issue happened in all my Qform and Qwidget.
          I just simply can figure out the solution, could you give me some advice directly? like how am I supposed to change the path or give a test on your environment?

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

          @CHHC
          You have a choice, like I wrote in that other thread I gave you a link for (please read through it carefully):

          • If you want to stick with Qt resources you will have to read up on how to do that for a Python script/program. I referenced a tutorial there at https://www.pythonguis.com/tutorials/qresource-system/, I think you end up having to run something like pyrcc5 resources.qrc -o resources.py command to generate a resources.py you can use. I have never used this.

          • I said there that if you want to avoid this "resources" way of doing things you could instead keep you .jpg etc. file(s) as external files on disk. Then you can address those files directly without going via resources. But be aware of what I said to the user in that thread: if the file(s) use a relative path you will need, from your Python script, to set the current working directory appropriately so that the relative paths are correctly found at runtime.

          C 1 Reply Last reply
          1
          • JonBJ JonB

            @CHHC
            You have a choice, like I wrote in that other thread I gave you a link for (please read through it carefully):

            • If you want to stick with Qt resources you will have to read up on how to do that for a Python script/program. I referenced a tutorial there at https://www.pythonguis.com/tutorials/qresource-system/, I think you end up having to run something like pyrcc5 resources.qrc -o resources.py command to generate a resources.py you can use. I have never used this.

            • I said there that if you want to avoid this "resources" way of doing things you could instead keep you .jpg etc. file(s) as external files on disk. Then you can address those files directly without going via resources. But be aware of what I said to the user in that thread: if the file(s) use a relative path you will need, from your Python script, to set the current working directory appropriately so that the relative paths are correctly found at runtime.

            C Offline
            C Offline
            CHHC
            wrote on last edited by
            #5

            @JonB Much appreciate.
            I've solved the problem under your instruction. Here are the test results:
            I've found that under the Win 10 you can't directly use .qrc file(s) every time it will feedback

            Could not create pixmap from
            

            But here is the point: this method work just fine under the win 8 or win7 with Python 3.6 or maybe below(I've only tested on the other two computers: one with win 8.1 and python 3.6.2 another is win 7 with python 3.5.0. My friend, if you found the issue happened in another version of Python or windows system please let me know)

            I DO NOT KNOW WHY there be differences. But under the win 10 and python 3.9.6(my current development environment), this happens!

            here's what I do:
            By turning the .qrc file to .py and importing the file to my main code.
            step 1:
            Win + R turn on the CMD and locate the .qrc address.

            cd PATH
            

            step 2:
            use the code below in CMD.

            pyrcc5 filename.qrc -o filename.py
            

            step 3:
            add a line at the beginning in your main python code:

            import filename
            

            As for your mentioned method number 2. it works fine for all scenarios. Of course, we can use the img resources directly. BUT, if the project involved enormous forms, Imgs, icons, pictures. I do recommend you use the .ui directly by the loadUI() method.

            1 Reply Last reply
            0

            • Login

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