Search code examples
pythonpyqtqt5pyqt5qapplication

PyQt5 - Python | QApplication.setStyle not working


I am trying to set custom style to my PyQt5 application using the setStyle() method but it doesn't work.

I am also not entirely sure about where this should be put.

In my main I tried doing :

if __name__ == '__main__':

    QApplication.setStyle("mac") #here
    app = QApplication(sys.argv)
    splash_pix = QPixmap('../resource/logo.png')
    start = time.time()
    splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
    splash.show()
    while time.time() - start < 1:
        time.sleep(0.003)
        app.processEvents()
    ex = Fy360()
    splash.finish(ex)
    sys.exit(app.exec_())

Edit : Upon importing from PyQt5.QtWidgets import QStyleFactory and printing the QStyleFactory.keys() I gotthe output as:

[u'Windows', u'Fusion']

why are there only these options?

Whats going wrong here?


Solution

  • Some styles are dependent on the OS, others are not, for example the Mac style is only for Mac OS, or for example fusion is compatible for several OS.

    Some styles (for example gtk) can be configured as follows:

    Based on the discussion :

    • Install qt5-styleplugins and qt5ct
    • Set environment variable in /etc/environment QT_QPA_PLATFORMTHEME=qt5ct
    • Restart the system
    • Start qt5ct and select gtk2