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. Icons from Resources not showing up in QPushButton or QToolButton
Forum Updated to NodeBB v4.3 + New Features

Icons from Resources not showing up in QPushButton or QToolButton

Scheduled Pinned Locked Moved Solved Qt for Python
31 Posts 5 Posters 17.1k Views 1 Watching
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #19

    What version of PySide2 are you using ?

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

    Oak77O 1 Reply Last reply
    0
    • SGaistS SGaist

      What version of PySide2 are you using ?

      Oak77O Offline
      Oak77O Offline
      Oak77
      wrote on last edited by
      #20

      @SGaist I don't know if this is a proper way to find out, but versions are listed:

      > pip install --upgrade PySide2
      Defaulting to user installation because normal site-packages is not writeable
      Requirement already up-to-date: PySide2 in /usr/lib64/python3.6/site-packages (5.15.0a1.dev1584103015)
      Requirement already satisfied, skipping upgrade: shiboken2==5.15.0a1.dev1584103015 in /usr/lib64/python3.6/site-packages (from PySide2) (5.15.0a1.dev1584103015)
      
      
      Oak77O 1 Reply Last reply
      0
      • Oak77O Oak77

        @SGaist I don't know if this is a proper way to find out, but versions are listed:

        > pip install --upgrade PySide2
        Defaulting to user installation because normal site-packages is not writeable
        Requirement already up-to-date: PySide2 in /usr/lib64/python3.6/site-packages (5.15.0a1.dev1584103015)
        Requirement already satisfied, skipping upgrade: shiboken2==5.15.0a1.dev1584103015 in /usr/lib64/python3.6/site-packages (from PySide2) (5.15.0a1.dev1584103015)
        
        
        Oak77O Offline
        Oak77O Offline
        Oak77
        wrote on last edited by
        #21

        OK, there are example apps that come with PySide2. Now I went into this one, which is using resource file:

        /usr/lib64/python3.6/site-packages/PySide2/examples/widgets/animation/appchooser/
        

        ...and run it:

        > python3 ./appchooser.py
        QPixmap::scaled: Pixmap is a null pixmap
        QPixmap::scaled: Pixmap is a null pixmap
        QPixmap::scaled: Pixmap is a null pixmap
        QPixmap::scaled: Pixmap is a null pixmap
        QPixmap::scaled: Pixmap is a null pixmap
        QPixmap::scaled: Pixmap is a null pixmap
        QPixmap::scaled: Pixmap is a null pixmap
        QPixmap::scaled: Pixmap is a null pixmap
        

        and I see only white blank window. Could someone try to run this example app and let me know it it is working? I wonder, if it's connected to this issue I'm experiencing with resource files.

        Oak77O 1 Reply Last reply
        0
        • Oak77O Oak77

          OK, there are example apps that come with PySide2. Now I went into this one, which is using resource file:

          /usr/lib64/python3.6/site-packages/PySide2/examples/widgets/animation/appchooser/
          

          ...and run it:

          > python3 ./appchooser.py
          QPixmap::scaled: Pixmap is a null pixmap
          QPixmap::scaled: Pixmap is a null pixmap
          QPixmap::scaled: Pixmap is a null pixmap
          QPixmap::scaled: Pixmap is a null pixmap
          QPixmap::scaled: Pixmap is a null pixmap
          QPixmap::scaled: Pixmap is a null pixmap
          QPixmap::scaled: Pixmap is a null pixmap
          QPixmap::scaled: Pixmap is a null pixmap
          

          and I see only white blank window. Could someone try to run this example app and let me know it it is working? I wonder, if it's connected to this issue I'm experiencing with resource files.

          Oak77O Offline
          Oak77O Offline
          Oak77
          wrote on last edited by
          #22

          I somehow progressed a bit with the issue. I tried another Python, the virtual environment that I set during some of tutorials. I installed a PySide2 into that venv and when running my test application in that environment, I can see 2 more pictures in QLabels (actualy those which should work).

          alt text

          But what is interesting nad unfortunate, the icons on the QPushButtons still don't work (the 2 that are shown are assigned via direct link, not a resource file). Icons are in different resource file (iconsres.qrc/icons) from the images (imgs.qrc/img), as is visible in the tree depicted in the screenshot.

          Also, when I ran the AppChooser example from PySide2 example set, it was working with the venv.

          So I did "pip uninstall pyside2" and "pip uninstall shoboken2" and then "pip install shoboken2" and "pip install pyside2", but it didn't help.

          I have two conclusions:

          1. Something is broken in my system Python. I have no idea how to fix it.
          2. There's something wrong with the iconsres.qrc and also with new testres.qrc, third resource I tried to create in the test project. The 2nd resource file imgs.qrc is valid. But I don't know what went wrong, what's the difference between them.

          Any advices for further steps appreciated.

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

            Can you provide a minimal example with all files that allows to reproduce your issue ?

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

            Oak77O 1 Reply Last reply
            0
            • Oak77O Offline
              Oak77O Offline
              Oak77
              wrote on last edited by Oak77
              #24

              @Denni-0 Yep, the thing is, that your modified PyQt5 code works on my system Python, but does not work on the virtual environment Python! So the exact oposite of the case of PySide2 version... It gets even more confusing. Obviously on both is installed the same PyQt5 and PySide2 package.

              1 Reply Last reply
              0
              • SGaistS SGaist

                Can you provide a minimal example with all files that allows to reproduce your issue ?

                Oak77O Offline
                Oak77O Offline
                Oak77
                wrote on last edited by
                #25

                @SGaist Yep, I created this one. Test12.zip

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

                  Since you gave an alias to each entry of the qrc file, use that allias to access the images.

                  For example:

                  self.pic1box.setPixmap(QPixmap(":/icons/qtlogo"))
                  

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

                  Oak77O 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Since you gave an alias to each entry of the qrc file, use that allias to access the images.

                    For example:

                    self.pic1box.setPixmap(QPixmap(":/icons/qtlogo"))
                    
                    Oak77O Offline
                    Oak77O Offline
                    Oak77
                    wrote on last edited by Oak77
                    #27

                    @SGaist Tested, wierd results gets wierder. There should be no difference between usage of alias and file name. But guess what - it still doesn't work in my system environment Python, but in the virtual environment Python, it works with aliases, but doesn't with file names!
                    Just look at the last screenshot (some 5 posts above), where it works both with the alias and the file name, as it should (it's two unscaled QtLogo images on the right).

                    Now it looks like this: On the left is app run in system environment or in venv using file names and on the right using virtual Python environment with aliases:
                    screenshots minimal

                    By now I know it's not really the code, but this uncertainty and instability is not a hair smaller concern anyway. One cannot deliver reliable app, not knowing what's happening.

                    I believe it has to be in the Python itself. There must be some difference between the package distributed in OpenSUSE:

                    > python3 --version
                    Python 3.6.10
                    > pip show PySide2
                    Name: PySide2
                    Version: 5.14.1
                    Summary: Python bindings for the Qt cross-platform application and UI framework
                    Home-page: https://www.pyside.org
                    Author: Qt for Python Team
                    Author-email: pyside@qt-project.org
                    License: LGPL
                    Location: /usr/lib64/python3.6/site-packages
                    Requires: shiboken2
                    

                    ...and the virtual environment:

                    > ~/Coding/Projects/venv/bin/python3 --version
                    Python 3.6.10
                    > ~/Coding/Projects/venv/bin/pip3 show PySide2
                    Name: PySide2
                    Version: 5.14.1
                    Summary: Python bindings for the Qt cross-platform application and UI framework
                    Home-page: https://www.pyside.org
                    Author: Qt for Python Team
                    Author-email: pyside@qt-project.org
                    License: LGPL
                    Location: ~/Coding/Projects/venv/lib/python3.6/site-packages
                    Requires: shiboken2
                    

                    They look same, but there must be a glitch somewhere.

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

                      Sill question but, did you install both using pip ?

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

                      Oak77O 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Sill question but, did you install both using pip ?

                        Oak77O Offline
                        Oak77O Offline
                        Oak77
                        wrote on last edited by
                        #29

                        @SGaist The system environment Python is installed via YaST from official OpenSuSE repository. As for virtual environment, I already forgot how I did it (it was according to tutorial), but I think it was like "python3 -m venv venv-name" (so actually based on the system one). From there, everything was done like:

                        pip install Shoboken2
                        pip install PySide2
                        

                        When trying to update:

                        pip install --upgrade Shoboken2
                        pip install --upgrade PySide2
                        

                        ...it says they're up-to-date.

                        I uninstalled Python from my system and then installed it back (the same way via YaST) and then uninstalled both Shoboken2 and PySide2, but nothing helped.

                        Oak77O 1 Reply Last reply
                        0
                        • Oak77O Oak77

                          @SGaist The system environment Python is installed via YaST from official OpenSuSE repository. As for virtual environment, I already forgot how I did it (it was according to tutorial), but I think it was like "python3 -m venv venv-name" (so actually based on the system one). From there, everything was done like:

                          pip install Shoboken2
                          pip install PySide2
                          

                          When trying to update:

                          pip install --upgrade Shoboken2
                          pip install --upgrade PySide2
                          

                          ...it says they're up-to-date.

                          I uninstalled Python from my system and then installed it back (the same way via YaST) and then uninstalled both Shoboken2 and PySide2, but nothing helped.

                          Oak77O Offline
                          Oak77O Offline
                          Oak77
                          wrote on last edited by Oak77
                          #30

                          OK, I found a cause. Not the root cause, but at least how to "replicate" this issue.

                          I found out, that apart from PySide2 installation using pip command, a totally different intallation is coexisting in my system, which I can see in my YaST software manager, named "Python3-PySide2". When I remove it, the resource files starts to work in my system environment Python.

                          Interestingly enough, pip3 install/uninstall PySide2 command works without even noticing that system PySide2 package. And if it's removed by pip uninstall, PySide2 programs would claim there's no PySide2 installed. When installed back using pip3 install pyside2, they wouldn't run properly with resource files.

                          The bad new for me is, that I can't remove this package, because it then removes also some shiboken2-cpython libraries, that are essential to start a FreeCAD. I need this software, so I can't remove the system PySide2. And I don't know what exactly is broken there, so I can't fix it. I might ask in OpenSUSE forums.

                          One more note - the programs look differently when the system PySide2 package is/is-not inistalled. Like another style sheet is used to render them (dark frames vs. light, small paddings in buttons and textboxes vs. large, etcc).

                          For the time being, I will have to use virtual environment Python.

                          1 Reply Last reply
                          0
                          • alomA Offline
                            alomA Offline
                            alom
                            wrote on last edited by
                            #31

                            if possible in you working evn, I have had really nice result using conda instead of pip. It manages all the dependencies out side of python for you. You can quite easily create any combination of python version and qt5/pyside2, plus any other python libs you need for your project. Pycharm even comes with a Anaconda installer, but I keep my separated.

                            Maybe that can help you manage you envs

                            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