CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyqt-fluent-widgets

A fluent design widgets library based on PyQt5 providing modern Windows 11-style UI components

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

menu-command.mddocs/

Menu and Command System

Context menus, command bars, and system tray menus with fluent styling, animations, and modern interaction patterns. These components provide comprehensive command organization and user interaction capabilities.

Capabilities

Context Menus

Enhanced context menus with fluent design styling and smooth animations.

class RoundMenu(QMenu):
    def __init__(self, parent=None): ...
    def addAction(self, action: QAction) -> QAction: ...
    def addAction(self, text: str, slot=None, shortcut=None) -> QAction: ...
    def addSeparator(self): ...
    def addMenu(self, menu: QMenu) -> QMenu: ...
    def exec(self, pos: QPoint, action: QAction = None) -> QAction: ...

class DWMMenu(QMenu):
    def __init__(self, parent=None): ...
    # System-integrated menu with Windows Desktop Window Manager integration

class LineEditMenu(RoundMenu):
    def __init__(self, parent=None): ...
    # Specialized menu for line edit controls with standard edit actions

class CheckableMenu(RoundMenu):
    def __init__(self, parent=None): ...
    def setDefaultAction(self, action: QAction): ...
    def defaultAction(self) -> QAction: ...

Usage Example:

from qfluentwidgets import RoundMenu, Action, FluentIcon as FIF

# Create context menu
context_menu = RoundMenu(self)

# Add actions
new_action = Action(FIF.ADD, "New", self)
open_action = Action(FIF.FOLDER, "Open", self)
save_action = Action(FIF.SAVE, "Save", self)

context_menu.addAction(new_action)
context_menu.addAction(open_action)
context_menu.addSeparator()
context_menu.addAction(save_action)

# Connect actions
new_action.triggered.connect(self.create_new)
open_action.triggered.connect(self.open_file)
save_action.triggered.connect(self.save_file)

# Show menu on right-click
def show_context_menu(self, pos):
    context_menu.exec(self.mapToGlobal(pos))
    
widget.setContextMenuPolicy(Qt.CustomContextMenu)
widget.customContextMenuRequested.connect(show_context_menu)

System Tray Menus

Specialized menus for system tray applications with proper system integration.

class SystemTrayMenu(QMenu):
    def __init__(self, parent=None): ...
    def addAction(self, action: QAction) -> QAction: ...
    def addAction(self, text: str, slot=None) -> QAction: ...

class CheckableSystemTrayMenu(SystemTrayMenu):
    def __init__(self, parent=None): ...
    def setDefaultAction(self, action: QAction): ...

Usage Example:

from qfluentwidgets import SystemTrayMenu, FluentIcon as FIF
from PyQt5.QtWidgets import QSystemTrayIcon

# System tray menu
tray_menu = SystemTrayMenu()

# Add tray actions
show_action = Action(FIF.VIEW, "Show Window", self)
settings_action = Action(FIF.SETTING, "Settings", self)
quit_action = Action(FIF.POWER_BUTTON, "Quit", self)

tray_menu.addAction(show_action)
tray_menu.addAction(settings_action)
tray_menu.addSeparator()
tray_menu.addAction(quit_action)

# Connect actions
show_action.triggered.connect(self.show_window)
settings_action.triggered.connect(self.show_settings)
quit_action.triggered.connect(self.quit_application)

# Create system tray icon
tray_icon = QSystemTrayIcon(FIF.APP.icon(), self)
tray_icon.setContextMenu(tray_menu)
tray_icon.show()

Command Bars

Modern command organization with ribbon-style interfaces and grouped actions.

class CommandBar(QWidget):
    def __init__(self, parent=None): ...
    def addAction(self, action: QAction): ...
    def addSeparator(self): ...
    def addWidget(self, widget: QWidget): ...
    def setToolButtonStyle(self, style: Qt.ToolButtonStyle): ...

class CommandButton(QToolButton):
    def __init__(self, parent=None): ...
    def __init__(self, icon: Union[FluentIconBase, QIcon, str], parent=None): ...
    def __init__(self, text: str, parent=None): ...
    def __init__(self, icon: Union[FluentIconBase, QIcon, str], text: str, parent=None): ...

class CommandBarView(QWidget):
    def __init__(self, parent=None): ...
    def addCommandBar(self, commandBar: CommandBar): ...
    def removeCommandBar(self, commandBar: CommandBar): ...

Usage Example:

from qfluentwidgets import CommandBar, CommandButton, CommandBarView, FluentIcon as FIF

# Create command bar
command_bar = CommandBar(self)
command_bar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

# Add command buttons
new_btn = CommandButton(FIF.ADD, "New")
open_btn = CommandButton(FIF.FOLDER, "Open")
save_btn = CommandButton(FIF.SAVE, "Save")

command_bar.addWidget(new_btn)
command_bar.addWidget(open_btn)
command_bar.addSeparator()
command_bar.addWidget(save_btn)

# Connect commands
new_btn.clicked.connect(self.create_new_document)
open_btn.clicked.connect(self.open_document)
save_btn.clicked.connect(self.save_document)

# Command bar container
command_view = CommandBarView(self)
command_view.addCommandBar(command_bar)

# Multiple command bars
edit_bar = CommandBar(self)
edit_bar.addWidget(CommandButton(FIF.CUT, "Cut"))
edit_bar.addWidget(CommandButton(FIF.COPY, "Copy"))
edit_bar.addWidget(CommandButton(FIF.PASTE, "Paste"))

command_view.addCommandBar(edit_bar)

Action System

Enhanced action system with fluent design integration and icon support.

class Action(QAction):
    def __init__(self, parent=None): ...
    def __init__(self, text: str, parent=None): ...
    def __init__(self, icon: Union[FluentIconBase, QIcon, str], text: str, parent=None): ...
    def setIcon(self, icon: Union[FluentIconBase, QIcon, str]): ...

class Icon(QIcon):
    def __init__(self, icon: Union[FluentIconBase, QIcon, str]): ...

Usage Example:

from qfluentwidgets import Action, Icon, FluentIcon as FIF

# Create actions with fluent icons
file_actions = [
    Action(FIF.ADD, "New File", self),
    Action(FIF.FOLDER, "Open File", self),
    Action(FIF.SAVE, "Save File", self),
    Action(FIF.SAVE_AS, "Save As", self),
]

# Set shortcuts
file_actions[0].setShortcut("Ctrl+N")
file_actions[1].setShortcut("Ctrl+O")
file_actions[2].setShortcut("Ctrl+S")
file_actions[3].setShortcut("Ctrl+Shift+S")

# Connect to slots
for action in file_actions:
    action.triggered.connect(self.handle_file_action)

def handle_file_action(self):
    sender = self.sender()
    print(f"Action triggered: {sender.text()}")

Menu Styling and Themes

All menu components automatically adapt to the current theme:

# Menu styling is handled automatically
# Custom styling can be applied through stylesheets

class MenuStyleSheet:
    LIGHT_THEME = """
        QMenu {
            background-color: white;
            border: 1px solid #e0e0e0;
            border-radius: 8px;
        }
        QMenu::item {
            padding: 8px 20px;
            border-radius: 4px;
        }
        QMenu::item:selected {
            background-color: #f0f0f0;
        }
    """
    
    DARK_THEME = """
        QMenu {
            background-color: #2b2b2b;
            border: 1px solid #3c3c3c;
            border-radius: 8px;
        }
        QMenu::item {
            padding: 8px 20px;
            border-radius: 4px;
            color: white;
        }
        QMenu::item:selected {
            background-color: #404040;
        }
    """

Usage Example:

from qfluentwidgets import isDarkTheme, FluentStyleSheet

# Apply fluent styling
FluentStyleSheet.MENU.apply(menu)

# Custom styling based on theme
if isDarkTheme():
    menu.setStyleSheet(MenuStyleSheet.DARK_THEME)
else:
    menu.setStyleSheet(MenuStyleSheet.LIGHT_THEME)

Advanced Menu Features

Hierarchical Menus

# Create nested menus
file_menu = RoundMenu("File", self)
recent_menu = RoundMenu("Recent Files", self)

# Add recent files
recent_files = ["document1.txt", "document2.txt", "document3.txt"]
for file_name in recent_files:
    action = Action(FIF.DOCUMENT, file_name, self)
    action.triggered.connect(lambda checked, f=file_name: self.open_recent_file(f))
    recent_menu.addAction(action)

# Add submenu
file_menu.addMenu(recent_menu)

Dynamic Menu Updates

class DynamicMenu(RoundMenu):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.aboutToShow.connect(self.update_menu)
        
    def update_menu(self):
        self.clear()
        
        # Rebuild menu based on current state
        current_items = self.get_current_items()
        for item in current_items:
            action = Action(item['icon'], item['text'], self)
            action.triggered.connect(item['callback'])
            self.addAction(action)

Menu with Custom Widgets

# Add custom widgets to menus
custom_menu = RoundMenu(self)

# Add standard actions
custom_menu.addAction(Action(FIF.SETTING, "Settings", self))
custom_menu.addSeparator()

# Add custom widget
widget_action = QWidgetAction(self)
custom_widget = QWidget()
layout = QHBoxLayout(custom_widget)

slider = Slider(Qt.Horizontal)
label = BodyLabel("Volume")
layout.addWidget(label)
layout.addWidget(slider)

widget_action.setDefaultWidget(custom_widget)
custom_menu.addAction(widget_action)

Keyboard and Accessibility

Menu components include full keyboard navigation and accessibility support:

# Keyboard shortcuts are automatically handled
action.setShortcut(QKeySequence("Ctrl+N"))

# Mnemonics for keyboard navigation
action.setText("&New File")  # Alt+N activates

# Accessibility
action.setToolTip("Create a new file")
action.setStatusTip("Create a new document")
action.setWhatsThis("This action creates a new file in the current directory")

# Screen reader support
menu.setAccessibleName("File Menu")
menu.setAccessibleDescription("Menu containing file operations")

Install with Tessl CLI

npx tessl i tessl/pypi-pyqt-fluent-widgets

docs

buttons.md

dialog-notification.md

display-widgets.md

index.md

input-controls.md

layout-animation.md

list-view-widgets.md

material-effects.md

menu-command.md

multimedia.md

settings-config.md

theme-styling.md

window-navigation.md

tile.json