https://github.com/hubenchang0515/QtTheme

Qt Theme is a pure qss project that can easily improve the style of existing projects.

Supports C++, PyQt5, PyQt6, PySide2, PySide6, and is published on GitHub Pages as WebAssembly.



Here is a demo of its use on Python, first install it:

pip install QtTheme

Alternatively, without installing QtTheme, you can export a single-style qrc resource package through the online website. Use RCC to add it to your project?
Let AI write an UI for me as an style example:

Qt Code:
  1. # Generated by ChatGPT
  2. import sys
  3. from PyQt5.QtCore import Qt
  4.  
  5. class MyWindow(QDialog):
  6. def __init__(self):
  7. super().__init__()
  8. self.setWindowTitle("PyQt5 Widgets Example")
  9. self.setGeometry(100, 100, 400, 300)
  10.  
  11. # Create layouts
  12. main_layout = QVBoxLayout() # Vertical layout for the whole window
  13. form_layout = QVBoxLayout() # Layout for the form
  14.  
  15. # Add a QLabel and QLineEdit (text input)
  16. self.label = QLabel("Enter your name:", self)
  17. self.text_input = QLineEdit(self)
  18.  
  19. form_layout.addWidget(self.label)
  20. form_layout.addWidget(self.text_input)
  21.  
  22. # Add a QComboBox (dropdown)
  23. self.combo_label = QLabel("Select your favorite color:", self)
  24. self.combo_box = QComboBox(self)
  25. self.combo_box.addItems(["Red", "Green", "Blue", "Yellow"])
  26.  
  27. form_layout.addWidget(self.combo_label)
  28. form_layout.addWidget(self.combo_box)
  29.  
  30. # Add a QCheckBox
  31. self.check_box = QCheckBox("I agree to the terms and conditions", self)
  32.  
  33. form_layout.addWidget(self.check_box)
  34.  
  35. # Add a QRadioButton (grouped)
  36. self.radio_label = QLabel("Choose your preferred language:", self)
  37. self.radio_button_english = QRadioButton("English", self)
  38. self.radio_button_french = QRadioButton("French", self)
  39. self.radio_button_spanish = QRadioButton("Spanish", self)
  40.  
  41. # Add the radio buttons to a horizontal layout
  42. radio_layout = QHBoxLayout()
  43. radio_layout.addWidget(self.radio_button_english)
  44. radio_layout.addWidget(self.radio_button_french)
  45. radio_layout.addWidget(self.radio_button_spanish)
  46.  
  47. form_layout.addWidget(self.radio_label)
  48. form_layout.addLayout(radio_layout)
  49.  
  50. # Add a QPushButton
  51. self.submit_button = QPushButton("Submit", self)
  52. self.submit_button.clicked.connect(self.on_button_click)
  53.  
  54. # Add an exit button
  55. self.exit_button = QPushButton("Exit", self)
  56.  
  57. button_layout = QHBoxLayout()
  58. button_layout.addWidget(self.submit_button)
  59. button_layout.addWidget(self.exit_button)
  60.  
  61. # Add the form layout to the main layout
  62. main_layout.addLayout(form_layout)
  63. main_layout.addLayout(button_layout)
  64.  
  65. # Set the window layout
  66. self.setLayout(main_layout)
  67.  
  68. def on_button_click(self):
  69. name = self.text_input.text()
  70. favorite_color = self.combo_box.currentText()
  71. is_agree = self.check_box.isChecked()
  72. preferred_language = "None"
  73.  
  74. if self.radio_button_english.isChecked():
  75. preferred_language = "English"
  76. elif self.radio_button_french.isChecked():
  77. preferred_language = "French"
  78. elif self.radio_button_spanish.isChecked():
  79. preferred_language = "Spanish"
  80.  
  81. print(f"Name: {name}")
  82. print(f"Favorite Color: {favorite_color}")
  83. print(f"Agreed to Terms: {is_agree}")
  84. print(f"Preferred Language: {preferred_language}")
  85.  
  86. if __name__ == "__main__":
  87. app = QApplication(sys.argv)
  88. window = MyWindow()
  89. window.show()
  90. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode 

try to run it:



Import QtTheme, then read and set the style for the root widget through the Qt resource system:

Qt Code:
  1. import QtTheme.PyQt5
  2. from PyQt5.QtCore import QFile
  3.  
  4. class MyWindow(QDialog):
  5. def __init__(self):
  6. # ...
  7. qss = QFile(":/QtTheme/theme/Flat/Dark/Blue/Pink.qss")
  8. qss.open(QFile.OpenModeFlag.ReadOnly)
  9. self.setStyleSheet(qss.readAll().data().decode())
To copy to clipboard, switch view to plain text mode 



Finally, set the color for the widgets through QWidget.setProperty as needed:

Qt Code:
  1. class MyWindow(QDialog):
  2. def __init__(self):
  3. # ...
  4. qss = QFile(":/QtTheme/theme/Flat/Dark/Blue/Pink.qss")
  5. qss.open(QFile.OpenModeFlag.ReadOnly)
  6. self.setStyleSheet(qss.readAll().data().decode())
  7.  
  8. self.submit_button.setProperty("Color", "Primary")
  9. self.exit_button.setProperty("Color", "Danger")
To copy to clipboard, switch view to plain text mode