[PyQt] PyQt not using Qt themes on Linux

Giuseppe Corbelli corbelligiuseppe at mesdan.it
Wed Jan 10 13:16:48 GMT 2018


On 01/08/2018 11:38 AM, Alasdair B R Stewart wrote:
> Hi,
> 
> 
> 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! Though it does not 
> appear as an option to preview in, instead only showing: Breeze, 
> bb10dark, bb10bright, kvantum-dark, kvantum, cleanlooks, gtk2, cde, 
> motif, plastique, Windows, Fusion.
> 
> As it is a pre-built wheel PyQt only has Windows and Fusion as inbuilt 
> stylesheet options -
> 
>  >>> from PyQt5.QtWidgets import QStyleFactory
>  >>> print(QStyleFactory.keys())
> ['Windows', 'Fusion']
> 
> Running any scripts I've written using PyQt5 (installed via conda) 
> defaults to Windows when run, likely as they built PyQt on a Windows 
> machine. I also tried installing PyQt from pip, which overrides the 
> conda install. It instead 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.
> 
> Installing python3-pyqt* and running pyqt scripts using the 
> /usr/bin/python3.6 half works. The colours and some of the layout are 
> now ArcDark but there remain a few Fusion elements - guessing there is a 
> gtk theming issue here.
> 
> Does anyone know a way to fix this? Ideally, I would want this to run 
> with the conda version of python. Alternatively, is there anyway to use 
> the files from arc-kde github to manually specify the style for each 
> script?

Not sure if I completely understand but:
*) styles are defined as QT plugins
*) you can manually set the style with QApplication::setStyle

If you want to use the same style the relevant plugin must be accessible 
by the Qt installation you're using but should be loadable explicitly 
with QPluginLoader.

This is not pyqt specific stuff however.

-- 
Giuseppe Corbelli


More information about the PyQt mailing list