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.



  • @AbeStew
    If you do not get an answer for this here, I would recommend you consider joining PyQT mailing list pyqt@riverbankcomputing.com and posting there.



  • 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 use pip (or rather, pip3) to install PyQt5. 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 with pip3 not correctly computing/downloading the dependencies --- no matter what anyone says, it gets it wrong; I have to uninstall the whole pip3 stuff to get it working again. Hence I have had to completely steer of any pip3 stuff.

    I should probably try the PyQt forum myself for this sometime....


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.