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 theme not showing up on Linux

Icons from theme not showing up on Linux

Scheduled Pinned Locked Moved Solved Qt for Python
7 Posts 3 Posters 2.2k 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
    cle1109
    wrote on 14 Feb 2022, 09:33 last edited by cle1109
    #1

    I have been developing the GUI app MNELAB for a while now. Whereas I previously used PySide2, I recently switched to PySide6. Everything works, except that on Linux the icons do not show up anymore (I only get text).

    I use icon themes that I bundle with the app (inside the icons folder). In my main window, I set the theme search path as follows:

    QIcon.setThemeSearchPaths([str(Path(__file__).parent / "icons")])
    

    This works on Windows and macOS, but on Linux I do not see any icons. The path is correct, but the icons assigned with e.g. icon = QIcon.fromTheme("open-file") just contain a null pointer.

    I would be very grateful for any pointers in the right direction. To test this, you can pip install mnelab and then type mnelab to start the program.

    153848997-e9ce308e-9aa2-460e-a086-6e8f5fe94f87.png

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Feb 2022, 20:22 last edited by
      #5

      Do you have the QtSvg module installed ?

      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
      2
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 14 Feb 2022, 20:56 last edited by
        #2

        Hi,

        Just to rule out the obvious, can you successfully show this icon if you use the full path ?

        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
        0
        • C Offline
          C Offline
          cle1109
          wrote on 15 Feb 2022, 07:16 last edited by cle1109
          #3

          I will check that. Meanwhile, I have created an issue on GitHub, and someone has already tried it and the icons are showing for him. Maybe it's a problem specific to my Arch Linux (the other person was using Ubuntu).

          Could you try to pip install mnelab and then run it with mnelab to see if you get the icons? Please also let me know which Linux distribution you are using.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cle1109
            wrote on 17 Feb 2022, 12:50 last edited by cle1109
            #4

            OK, I made a minimal example to reproduce the issue:

            from pathlib import Path
            import sys
            
            from PySide6 import QtGui, QtWidgets
            
            
            class MainWindow(QtWidgets.QMainWindow):
                def __init__(self, parent=None):
                    super().__init__(parent)
                    file_menu = self.menuBar().addMenu("&File")
                    icon = QtGui.QIcon(str(Path(__file__).parent / 'open-file.svg'))
                    open_file_action = file_menu.addAction(icon, "&Open...", lambda: None)
                    toolbar = self.addToolBar("toolbar")
                    toolbar.addAction(open_file_action)
            
            
            app = QtWidgets.QApplication(sys.argv)
            window = MainWindow()
            window.show()
            sys.exit(app.exec())
            

            I saved this script as qt-icons.py. The icon open-file.svg is in the same folder as the script. I used this icon from the Google Material Design website (and renamed it to open-file.svg).

            Running this with python qt-icons.py, the app doesn't show the icon on my Arch Linux. It does work on macOS though. So I guess there is something wrong or missing on my Linux machine? Is there any way I can find out?

            A 1 Reply Last reply 12 Jul 2022, 20:27
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 17 Feb 2022, 20:22 last edited by
              #5

              Do you have the QtSvg module installed ?

              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
              2
              • C Offline
                C Offline
                cle1109
                wrote on 18 Feb 2022, 07:58 last edited by
                #6

                Indeed, the qt6-svg package was missing! Thanks for your help!

                1 Reply Last reply
                0
                • C cle1109
                  17 Feb 2022, 12:50

                  OK, I made a minimal example to reproduce the issue:

                  from pathlib import Path
                  import sys
                  
                  from PySide6 import QtGui, QtWidgets
                  
                  
                  class MainWindow(QtWidgets.QMainWindow):
                      def __init__(self, parent=None):
                          super().__init__(parent)
                          file_menu = self.menuBar().addMenu("&File")
                          icon = QtGui.QIcon(str(Path(__file__).parent / 'open-file.svg'))
                          open_file_action = file_menu.addAction(icon, "&Open...", lambda: None)
                          toolbar = self.addToolBar("toolbar")
                          toolbar.addAction(open_file_action)
                  
                  
                  app = QtWidgets.QApplication(sys.argv)
                  window = MainWindow()
                  window.show()
                  sys.exit(app.exec())
                  

                  I saved this script as qt-icons.py. The icon open-file.svg is in the same folder as the script. I used this icon from the Google Material Design website (and renamed it to open-file.svg).

                  Running this with python qt-icons.py, the app doesn't show the icon on my Arch Linux. It does work on macOS though. So I guess there is something wrong or missing on my Linux machine? Is there any way I can find out?

                  A Offline
                  A Offline
                  A.N.E.
                  wrote on 12 Jul 2022, 20:27 last edited by
                  #7

                  @cle1109 I am getting similiar behaviour with Windows app. I have created a test app with a frame and a push button inside that has an icon attached to it with some style applicated to it. When I compile de ui with pyside6-uic and even after changing location of icons channging u"../xxxxxx.ico" to u"./xxxx.ico" and run the app the icons do not apear on the window. But if I compile the ui with pyside2 it works fine and all icons turn up on the window.

                  It seems simple but I can“t get the reason to fix it.

                  Any ideas would be grateful.

                  Regards,[link text]Qt Designer_Ui_Form.png Form.png

                  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