### Run Example Application Source: https://github.com/zhiyiyo/pyqt-fluent-widgets/blob/master/docs/source/quick-start.md Navigate to the examples directory and run the demo script after installation. ```python cd examples/gallery python demo.py ``` -------------------------------- ### Install Full-Featured Version Source: https://github.com/zhiyiyo/pyqt-fluent-widgets/blob/master/docs/source/quick-start.md Use this command to install the full-featured version of the library, including all components. ```shell pip install "PyQt-Fluent-Widgets[full]" -i https://pypi.org/simple/ ``` -------------------------------- ### Install Lite Version Source: https://github.com/zhiyiyo/pyqt-fluent-widgets/blob/master/docs/source/quick-start.md Use this command to install the lite version of the library, which excludes AcrylicLabel. ```shell pip install PyQt-Fluent-Widgets -i https://pypi.org/simple/ ``` -------------------------------- ### Define and Load Application Configuration Source: https://github.com/zhiyiyo/pyqt-fluent-widgets/blob/master/docs/source/settings.md Define configuration items using `ConfigItem` subclasses and load them from a JSON file using `QConfig`. This example demonstrates various `ConfigItem` types like `BoolValidator`, `ColorConfigItem`, `OptionsConfigItem`, `RangeConfigItem`, and `EnumSerializer`. ```python class MvQuality(Enum): """ MV quality enumeration class """ FULL_HD = "Full HD" HD = "HD" SD = "SD" LD = "LD" @staticmethod def values(): return [q.value for q in MvQuality] class Config(QConfig): """ Config of application """ # main window enableAcrylic = ConfigItem("MainWindow", "EnableAcrylic", False, BoolValidator()) playBarColor = ColorConfigItem("MainWindow", "PlayBarColor", "#225C7F") themeMode = OptionsConfigItem("MainWindow", "ThemeMode", "Light", OptionsValidator(["Light", "Dark", "Auto"])), restart=True) recentPlaysNumber = RangeConfigItem("MainWindow", "RecentPlayNumbers", 300, RangeValidator(10, 300)) # online onlineMvQuality = OptionsConfigItem("Online", "MvQuality", MvQuality.FULL_HD, OptionsValidator(MvQuality), EnumSerializer(MvQuality)) # create config object and initialize it cfg = Config() qconfig.load('config/config.json', cfg) ``` -------------------------------- ### Custom Avatar Navigation Widget Source: https://github.com/zhiyiyo/pyqt-fluent-widgets/blob/master/docs/source/navigation.md Example of creating a custom navigation menu item by inheriting from NavigationWidget. This widget displays an avatar and a username, and customizes the paintEvent for appearance. ```python from qfluentwidgets import NavigationWidget class AvatarWidget(NavigationWidget): """ Avatar widget """ def __init__(self, parent=None): super().__init__(isSelectable=False, parent=parent) self.avatar = QImage('resource/shoko.png').scaled( 24, 24, Qt.KeepAspectRatio, Qt.SmoothTransformation) def paintEvent(self, e): painter = QPainter(self) painter.setRenderHints( QPainter.SmoothPixmapTransform | QPainter.Antialiasing) painter.setPen(Qt.NoPen) if self.isPressed: painter.setOpacity(0.7) # draw background if self.isEnter: c = 255 if isDarkTheme() else 0 painter.setBrush(QColor(c, c, c, 10)) painter.drawRoundedRect(self.rect(), 5, 5) # draw avatar painter.setBrush(QBrush(self.avatar)) painter.translate(8, 6) painter.drawEllipse(0, 0, 24, 24) painter.translate(-8, -6) if not self.isCompacted: painter.setPen(Qt.white if isDarkTheme() else Qt.black) font = QFont('Segoe UI') font.setPixelSize(14) painter.setFont(font) painter.drawText(QRect(44, 0, 255, 36), Qt.AlignVCenter, 'zhiyiYo') ``` -------------------------------- ### Automatic Stylesheet Switching Based on Theme Source: https://github.com/zhiyiyo/pyqt-fluent-widgets/blob/master/docs/source/theme.md Inherit `StyleSheetBase` and override the `path()` method to automatically switch between light and dark theme QSS files. This example shows how to define stylesheet names and dynamically generate their paths based on the current theme. ```python from enum import Enum from qfluentwidgets import StyleSheetBase, Theme, isDarkTheme, qconfig class StyleSheet(StyleSheetBase, Enum): """ Style sheet """ MAIN_WINDOW = "main_window" def path(self, theme=Theme.AUTO): theme = qconfig.theme if theme == Theme.AUTO else theme return f"app/resource/qss/{theme.value.lower()}/{self.value}.qss" class MainWindow(QWidget): def __init__(self, parent=None): super().__init__(parent=parent) # apply style sheet to main window StyleSheet.MAIN_WINDOW.apply(self) ``` -------------------------------- ### Custom Icon Implementation Source: https://github.com/zhiyiyo/pyqt-fluent-widgets/blob/master/docs/source/icon.md Inherit from `FluentIconBase` and `Enum` to define custom icons. Override the `path()` method to specify the icon's file path, allowing it to change based on the theme. ```python from enum import Enum from qfluentwidgets import getIconColor, Theme, FluentIconBase class MyFluentIcon(FluentIconBase, Enum): """ Custom icons """ ADD = "Add" CUT = "Cut" COPY = "Copy" def path(self, theme=Theme.AUTO): return f':/icons/{self.value}_{getIconColor(theme)}.svg' ``` -------------------------------- ### NavigationInterface addWidget Method Signature Source: https://github.com/zhiyiyo/pyqt-fluent-widgets/blob/master/docs/source/navigation.md Signature for the addWidget method of NavigationInterface. This method is used to add navigation menu items to the panel. ```python def addWidget( self, routeKey: str, widget: NavigationWidget, onClick=None, position=NavigationItemPosition.TOP, tooltip: str = None, parentRouteKey: str = None ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.