After browsing on the forum, I found a nice looking theme style nonstandard library QT of pyqt5_ Material, this is the use of the third pyqt5 theme style library in addition to the previous application process.
qt_ The material contains a total of 25 theme styles. We can use them directly in the application. It is quite simple to use. The following is an illustration of the official example taken from the official website.
Issue QT to_ The boss of material non-standard library delivers tea!
1. Prepare
Back to business, QT_ As an independent python non-standard library, material also needs to be installed once, and installed by pip.
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple qt-material
My side is the effect that has been installed, which indicates that the installation has been successful.
After installation, import QT_ List of material module_ Themes interface to see how many theme style. xml files are provided.
from qt_material import list_themes # Import the pprint interface to print out more beautiful list data from pprint import pprint pprint('Total theme style:{} Seed!'.format(len(list_themes()))) pprint(list_themes()) # WARNING:root:qt_material must be imported after PySide or PyQt! # 'total theme styles: 26! ' # ['dark_amber.xml', # 'dark_blue.xml', # 'dark_cyan.xml', # 'dark_lightgreen.xml', # 'dark_pink.xml', # 'dark_purple.xml', # 'dark_red.xml', # 'dark_teal.xml', # 'dark_yellow.xml', # 'light_amber.xml', # 'light_blue.xml', # 'light_blue_500.xml', # 'light_cyan.xml', # 'light_cyan_500.xml', # 'light_lightgreen.xml', # 'light_lightgreen_500.xml', # 'light_orange.xml', # 'light_pink.xml', # 'light_pink_500.xml', # 'light_purple.xml', # 'light_purple_500.xml', # 'light_red.xml', # 'light_red_500.xml', # 'light_teal.xml', # 'light_teal_500.xml', # 'light_yellow.xml']
When developing pyqt5 applications, you can choose the theme style to use.
2. Use theme
After the installation is completed, when our application is directly imported and used, there will be beautiful styles and visual effects.
Here, we use our traditional method to create a pyqt5 application, and choose any theme style to use.
# Import the relevant python non-standard library required by the pyqt5 application to write the application of this test case. from PyQt5.QtWidgets import QWidget, QApplication from PyQt5.QtGui import QIcon import sys from qt_material import apply_stylesheet class HelloWorldUI(QWidget): def __init__(self): super(HelloWorldUI, self).__init__() self.init_ui() def init_ui(self): self.setWindowTitle('Hello World [Python concentration camp]') self.setWindowIcon(QIcon('python.ico')) # TODO: this example is to show apply_ For the usage of the stylesheet theme, components such as detailed buttons will not be added here.
Use this QT after writing_ The material module gives me the test case hello_ Add the expected theme style to the world to make it more beautiful.
First, import the style library into the current code block, and then call it directly when the main function starts the whole application.
if __name__ == '__main__': app = QApplication(sys.argv) apply_stylesheet(app, theme='dark_teal.xml') hello_world = HelloWorldUI() hello_world.show() sys.exit(app.exec_())
The following line of code block is the code block referenced by the theme style we added ourselves. When calling, one line of code is directly completed. Is it convenient?
apply_stylesheet(app, theme='dark_teal.xml')
In addition, we replace dark_ teal. The XML file can complete the reference to different styles, which is quite easy to use. For other style files, we have used list in the first step_ The themes are all listed.