initial fluent-widgets ui

This commit is contained in:
2025-08-14 18:45:16 +08:00
parent 746e83ab23
commit 4c66886257
1198 changed files with 805339 additions and 0 deletions

View File

@ -0,0 +1,114 @@
# coding:utf-8
import sys
from PySide6.QtCore import Qt
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QApplication, QWidget, QHBoxLayout
from qfluentwidgets import (FluentIcon, TransparentDropDownPushButton, RoundMenu, CommandBar, Action,
setTheme, Theme, setFont, CommandBarView, Flyout, FlyoutAnimationType,
ImageLabel, ToolButton, PushButton)
from qframelesswindow import FramelessWindow, StandardTitleBar
class Demo1(QWidget):
def __init__(self):
super().__init__()
# setTheme(Theme.DARK)
# self.setStyleSheet('Demo1{background: rgb(32, 32, 32)}')
self.hBoxLayout = QHBoxLayout(self)
self.commandBar = CommandBar(self)
self.dropDownButton = self.createDropDownButton()
self.hBoxLayout.addWidget(self.commandBar, 0)
# change button style
self.commandBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
# self.commandBar.setMenuDropDown(False)
# self.commandBar.setButtonTight(True)
# setFont(self.commandBar, 14)
self.addButton(FluentIcon.ADD, 'Add')
self.commandBar.addSeparator()
self.isEdit = False
self.commandBar.addAction(Action(FluentIcon.EDIT, 'Edit', triggered=self.onEdit, checkable=True))
self.addButton(FluentIcon.COPY, 'Copy')
self.addButton(FluentIcon.SHARE, 'Share')
# add custom widget
self.commandBar.addWidget(self.dropDownButton)
# add hidden actions
self.commandBar.addHiddenAction(Action(FluentIcon.SCROLL, 'Sort', triggered=lambda: print('排序')))
self.commandBar.addHiddenAction(Action(FluentIcon.SETTING, 'Settings', shortcut='Ctrl+S'))
self.resize(240, 40)
self.setWindowTitle('Drag window')
def addButton(self, icon, text):
action = Action(icon, text, self)
action.triggered.connect(lambda: print(text))
self.commandBar.addAction(action)
def onEdit(self):
self.isEdit = not self.isEdit
print('Enter edit mode' if self.isEdit else 'Exit edit mode')
def createDropDownButton(self):
button = TransparentDropDownPushButton('Menu', self, FluentIcon.MENU)
button.setFixedHeight(34)
setFont(button, 12)
menu = RoundMenu(parent=self)
menu.addActions([
Action(FluentIcon.COPY, 'Copy'),
Action(FluentIcon.CUT, 'Cut'),
Action(FluentIcon.PASTE, 'Paste'),
Action(FluentIcon.CANCEL, 'Cancel'),
Action('Select all'),
])
button.setMenu(menu)
return button
class Demo2(FramelessWindow):
def __init__(self):
super().__init__()
self.setTitleBar(StandardTitleBar(self))
self.vBoxLayout = QHBoxLayout(self)
self.imageLabel = ImageLabel('resource/pink_memory.jpg')
self.imageLabel.scaledToWidth(380)
self.imageLabel.clicked.connect(self.showCommandBar)
self.vBoxLayout.addWidget(self.imageLabel)
self.vBoxLayout.setContentsMargins(0, 80, 0, 0)
self.setStyleSheet('Demo2{background: white}')
self.setWindowTitle('Click Image 👇️🥵')
self.setWindowIcon(QIcon(":/qfluentwidgets/images/logo.png"))
def showCommandBar(self):
view = CommandBarView(self)
view.addAction(Action(FluentIcon.SHARE, 'Share'))
view.addAction(Action(FluentIcon.SAVE, 'Save'))
view.addAction(Action(FluentIcon.DELETE, 'Delete'))
view.addHiddenAction(Action(FluentIcon.APPLICATION, 'App', shortcut='Ctrl+A'))
view.addHiddenAction(Action(FluentIcon.SETTING, 'Settings', shortcut='Ctrl+S'))
view.resizeToSuitableWidth()
Flyout.make(view, self.imageLabel, self, FlyoutAnimationType.FADE_IN)
if __name__ == '__main__':
app = QApplication(sys.argv)
w1 = Demo1()
w1.show()
w2 = Demo2()
w2.show()
app.exec()

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

View File

@ -0,0 +1,75 @@
# coding:utf-8
import sys
from PySide6.QtCore import Qt
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QApplication, QWidget, QHBoxLayout, QLabel
from qfluentwidgets import RoundMenu, setTheme, Theme, Action, MenuAnimationType, MenuItemDelegate, CheckableMenu, MenuIndicatorType
from qfluentwidgets import FluentIcon as FIF
class Demo(QWidget):
def __init__(self):
super().__init__()
self.setLayout(QHBoxLayout())
self.label = QLabel('Right-click your mouse', self)
self.label.setAlignment(Qt.AlignCenter)
self.layout().addWidget(self.label)
self.resize(400, 400)
self.setStyleSheet('Demo{background: white} QLabel{font-size: 20px}')
# setTheme(Theme.DARK)
def contextMenuEvent(self, e):
menu = RoundMenu(parent=self)
# menu = CheckableMenu(parent=self, indicatorType=MenuIndicatorType.RADIO)
# NOTE: hide the shortcut key
# menu.view.setItemDelegate(MenuItemDelegate())
# add actions
menu.addAction(Action(FIF.COPY, 'Copy'))
menu.addAction(Action(FIF.CUT, 'Cut'))
menu.actions()[0].setCheckable(True)
menu.actions()[0].setChecked(True)
# add sub menu
submenu = RoundMenu("Add to", self)
submenu.setIcon(FIF.ADD)
submenu.addActions([
Action(FIF.VIDEO, 'Video'),
Action(FIF.MUSIC, 'Music'),
])
menu.addMenu(submenu)
# add actions
menu.addActions([
Action(FIF.PASTE, 'Paste'),
Action(FIF.CANCEL, 'Undo')
])
# add separator
menu.addSeparator()
menu.addAction(QAction(f'Select all', shortcut='Ctrl+A'))
# insert actions
menu.insertAction(
menu.actions()[-1], Action(FIF.SETTING, 'Settings', shortcut='Ctrl+S'))
menu.insertActions(
menu.actions()[-1],
[Action(FIF.HELP, 'Help', shortcut='Ctrl+H'),
Action(FIF.FEEDBACK, 'Feedback', shortcut='Ctrl+F')]
)
menu.actions()[-2].setCheckable(True)
menu.actions()[-2].setChecked(True)
# show menu
menu.exec(e.globalPos(), aniType=MenuAnimationType.DROP_DOWN)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Demo()
w.show()
app.exec()

View File

@ -0,0 +1,76 @@
# coding:utf-8
import sys
from PySide6.QtCore import Qt
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QApplication, QWidget, QSystemTrayIcon, QHBoxLayout, QLabel
from qfluentwidgets import Action, SystemTrayMenu, MessageBox, setTheme, Theme
class SystemTrayIcon(QSystemTrayIcon):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.setIcon(parent.windowIcon())
self.setToolTip('硝子酱一级棒卡哇伊🥰')
self.menu = SystemTrayMenu(parent=parent)
self.menu.addActions([
Action('🎤 唱'),
Action('🕺 跳'),
Action('🤘🏼 RAP'),
Action('🎶 Music'),
Action('🏀 篮球', triggered=self.ikun),
])
self.setContextMenu(self.menu)
def ikun(self):
content = """巅峰产生虚伪的拥护,黄昏见证真正的使徒 🏀
⠀⠰⢷⢿⠄
⠀⠀⠀⠀⠀⣼⣷⣄
⠀⠀⣤⣿⣇⣿⣿⣧⣿⡄
⢴⠾⠋⠀⠀⠻⣿⣷⣿⣿⡀
⠀⢀⣿⣿⡿⢿⠈⣿
⠀⠀⠀⢠⣿⡿⠁⠀⡊⠀⠙
⠀⠀⠀⢿⣿⠀⠀⠹⣿
⠀⠀⠀⠀⠹⣷⡀⠀⣿⡄
⠀⠀⠀⠀⣀⣼⣿⠀⢈⣧
"""
w = MessageBox(
title='坤家军!集合!',
content=content,
parent=self.parent()
)
w.yesButton.setText('献出心脏')
w.cancelButton.setText('你干嘛~')
w.exec()
class Demo(QWidget):
def __init__(self):
super().__init__()
# setTheme(Theme.DARK)
self.setLayout(QHBoxLayout())
self.label = QLabel('Right-click system tray icon', self)
self.label.setAlignment(Qt.AlignCenter)
self.layout().addWidget(self.label)
self.resize(500, 500)
self.setStyleSheet('Demo{background: white} QLabel{font-size: 20px}')
self.setWindowIcon(QIcon(':/qfluentwidgets/images/logo.png'))
self.systemTrayIcon = SystemTrayIcon(self)
self.systemTrayIcon.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Demo()
w.show()
app.exec()

View File

@ -0,0 +1,78 @@
# coding:utf-8
import sys
from PySide6 import QtGui
from PySide6.QtCore import Qt
from PySide6.QtGui import QIcon, QColor
from PySide6.QtWidgets import QApplication, QWidget, QLabel, QHBoxLayout
from qfluentwidgets import (RoundMenu, FluentIcon, Action, AvatarWidget, BodyLabel,
HyperlinkButton, CaptionLabel, setFont, setTheme, Theme, isDarkTheme)
class ProfileCard(QWidget):
""" Profile card """
def __init__(self, avatarPath: str, name: str, email: str, parent=None):
super().__init__(parent=parent)
self.avatar = AvatarWidget(avatarPath, self)
self.nameLabel = BodyLabel(name, self)
self.emailLabel = CaptionLabel(email, self)
self.logoutButton = HyperlinkButton(
'https://qfluentwidgets.com', '注销', self)
color = QColor(206, 206, 206) if isDarkTheme() else QColor(96, 96, 96)
self.emailLabel.setStyleSheet('QLabel{color: '+color.name()+'}')
color = QColor(255, 255, 255) if isDarkTheme() else QColor(0, 0, 0)
self.nameLabel.setStyleSheet('QLabel{color: '+color.name()+'}')
setFont(self.logoutButton, 13)
self.setFixedSize(307, 82)
self.avatar.setRadius(24)
self.avatar.move(2, 6)
self.nameLabel.move(64, 13)
self.emailLabel.move(64, 32)
self.logoutButton.move(52, 48)
class Demo(QWidget):
def __init__(self):
super().__init__()
# setTheme(Theme.DARK)
# self.setStyleSheet('Demo{background: rgb(32, 32, 32)}')
self.setStyleSheet('Demo{background: white}')
self.setLayout(QHBoxLayout())
self.label = BodyLabel('Right-click your mouse', self)
self.label.setAlignment(Qt.AlignCenter)
setFont(self.label, 18)
self.layout().addWidget(self.label)
self.resize(400, 400)
def contextMenuEvent(self, e) -> None:
menu = RoundMenu(parent=self)
# add custom widget
card = ProfileCard('resource/shoko.png', '硝子酱', 'shokokawaii@outlook.com', menu)
menu.addWidget(card, selectable=False)
# menu.addWidget(card, selectable=True, onClick=lambda: print('666'))
menu.addSeparator()
menu.addActions([
Action(FluentIcon.PEOPLE, '管理账户和设置'),
Action(FluentIcon.SHOPPING_CART, '支付方式'),
Action(FluentIcon.CODE, '兑换代码和礼品卡'),
])
menu.addSeparator()
menu.addAction(Action(FluentIcon.SETTING, '设置'))
menu.exec(e.globalPos())
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Demo()
w.show()
app.exec()

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB