Icons from theme not showing up on Linux
-
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 typemnelab
to start the program. -
Do you have the QtSvg module installed ?
-
Hi,
Just to rule out the obvious, can you successfully show this icon if you use the full path ?
-
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 withmnelab
to see if you get the icons? Please also let me know which Linux distribution you are using. -
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 iconopen-file.svg
is in the same folder as the script. I used this icon from the Google Material Design website (and renamed it toopen-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? -
Do you have the QtSvg module installed ?
-
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 iconopen-file.svg
is in the same folder as the script. I used this icon from the Google Material Design website (and renamed it toopen-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?@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]