PyQt not using Qt themes on Linux
-
I am running Ubuntu 17.10 and having difficulty getting PyQt to use the system theme. Since Gnome is the default desktop I have used Kvantum Manager to specify ArcDark as the system Qt5 theme. This works in the majority of applications - including Qt 5 Designer! However, running any scripts I've written using PyQt5 (installed via conda) defaults to Windows when run.
It looks like PyQt only has Windows and Fusion as inbuilt stylesheet options ->>> from PyQt5.QtWidgets import QStyleFactory
>>> print(QStyleFactory.keys())
['Windows', 'Fusion']In Qt Designer though the options are: Breeze, bb10dark, bb10bright, kvantum-dark, kvantum, cleanlooks, gtk2, cde, motif, plastique, Windows, Fusion.
I also tried installing PyQt from pip, which overrides the conda install (conda remove pyqt proposes removing whole bunch of core anaconda packages for some reason). However, it defaults to Fusion style but at least provides the error message "QApplication: invalid style override passed, ignoring it." Again only Windows and Fusion are recognised QStyleFactory keys for some reason.
Does anyone know a way to fix this? Alternatively, is there anyway to use the files from arc-kde github to manually specify the style for each script? Thanks in advance. -
Thanks @JonB. Dropped them an e-mail.
Further internet searching on the issue suggests that since pyqt (and same will apply to pyside) on conda and pip are pre-built wheels they do not recognize system themes. Conda defaults to Windows as they must have built pyqt on a Windows machine. Installing via apt python3-pyqt* and using the system Python (rather than the Anaconda install of Python) half works. It shows the right colours, but retains much of the overall Fusion look. The terminal also logs gtk errors when launching system file pickers etc. A few folk seem to have got alternative default themes (Plastique, CleanLooks etc) to work with PyQt by building it against a local install of Qt and qtstyleplugins. However, not found any threads on anyone having success with that using a custom theme. Not exactly the easiest to maintain solution either.
I am starting to think the best solution may be using a qss style sheet - with added benefit that could add a style picker dialogue that would let Windows users have a dark theme as well. Still a beginner with Qt so unsure if a qss file alone would be enough to provide a ArcDark look beyond the colours though?
-
@AbeStew
I am very much a beginner at Python/PyQt/Qt.This is probably OT, but reading what you are saying about "installation" you are probably ahead of me.
I install everything via standard
apt-get
, with no extra configuration or search paths. And everything "works". However (because of my IDE, PyCharm) I would like to usepip
(or rather,pip3
) to installPyQt5
. However, when I do so it craps up the system, such that the application no longer runs. I have tried this on various releases of Ubuntu, and they all go wrong. It is something to do withpip3
not correctly computing/downloading the dependencies --- no matter what anyone says, it gets it wrong; I have to uninstall the wholepip3
stuff to get it working again. Hence I have had to completely steer of anypip3
stuff.I should probably try the PyQt forum myself for this sometime....
-
I've seen this issue too, on Debian I've always found it much better to install PyQt via apt rather than Pip!
Hence my instructions here: https://github.com/nshiell/blue-log-viewer
The big issue now is that I can't package my app into an AppImage and get the styling to work.
The AppImage should have PyQy bundled in it, but the version inside the AppImage can't then inherit styling from the desktop.Fixing this is way beyond me and there is a heck of a lot of movement on KDE desktops with theming and application packaging.
When we have goodies like AppImage, Snappy, Flatpack and also Kvantum all existing at once I think PyQt theming is going to be tricky to get right :(