pythonpyqtpyqt5python-venv

Having issues getting PyQt5 + venv + qt5ct to play nicely


I'm working on a little PyQT5 application, which I'd like to run in a virtual environment. Now, having created a venv, and installed all required packages into the venv with pip, the application is running, and generally working fine.

But, I'm having issues with the theming. Now, I use qt5ct to manage my QT themes on my computer, but unfortunately, this doesn't seem to get picked up within the venv. If I run the application outside of the venv, the first line outputted in the console is qt5ct: using qt5ct plugin and the application is styled according to my choices in qt5ct. However, when running in the venv, I get no such line, and everything has default styling.

Now, I've printed os.environ['QT_QPA_PLATFORMTHEME']from within the virtual environment and verified that its set to qt5ct as it should be. It seems like qt5ct simply isn't getting exectured, I've tried to symlink the qt5ct executable in my venv bin folder, but, it didn't help anything.

Does anybody know how to use qt5ct setting to get applied to a pyqt5 app running in a python3-venv?


Solution

  • When you compile qt5ct, then 3 files are generated:

    The first is the application that allows you to configure qt5ct and the others are plugins. For qt5ct to work with the PyQt5 installed from pypi you must copy libqt5ct.so and libqt5ct-style.so to:

    respectively.

    If you have installed qt5ct using pacman then you must use the following steps:

    $ cp /usr/lib/qt/plugins/platformthemes/libqt5ct.so /path/of/your_venv/lib/python3.7/site-packages/PyQt5/Qt/plugins/platformthemes/
    $ mkdir /path/of/your_venv/lib/python3.7/site-packages/PyQt5/Qt/plugins/styles/
    $ cp /usr/lib/qt/plugins/styles/libqt5ct-style.so /path/of/your_venv/lib/python3.7/site-packages/PyQt5/Qt/plugins/styles/
    

    Where /path/of/your_venv is the path of your venv.