提交 d7df4155 编写于 作者: 之一Yo's avatar 之一Yo

添加更换主题的函数 `setTheme`

上级 2dc6bb7b
......@@ -9,7 +9,7 @@
project = 'PyQt-Fluent-Widgets'
copyright = '2023, zhiyiYo'
author = 'zhiyiYo'
release = 'v0.1.1'
release = 'v0.2.8'
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
......
......@@ -18,6 +18,9 @@
### Win10 Style Message Dialog
![](./_static/gallery/dialog_with_mask.gif)
### Navigation
![](./_static/gallery/navigation.gif)
### Flow Layout
![](./_static/gallery/flow_layout.gif)
......@@ -37,4 +40,4 @@
![](./_static/gallery/switch_button.gif)
### Tool Tip
![](./_static/gallery/tool_tip.gif)
![](./_static/gallery/tool_tip.gif)
\ No newline at end of file
......@@ -4,7 +4,7 @@ import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QApplication, QWidget
from qfluentwidgets import ColorPickerButton
from qfluentwidgets import ColorPickerButton, setTheme, Theme
class Demo(QWidget):
......@@ -16,6 +16,8 @@ class Demo(QWidget):
self.button.move(352, 312)
self.setStyleSheet("Demo{background:white}")
# setTheme(Theme.DARK)
if __name__ == '__main__':
# enable dpi scale
......
......@@ -2,7 +2,7 @@
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout
from qfluentwidgets import ComboBox
from qfluentwidgets import ComboBox, setTheme, Theme
class Demo(QWidget):
......@@ -14,9 +14,11 @@ class Demo(QWidget):
self.comboBox.setCurrentIndex(0)
self.comboBox.currentTextChanged.connect(print)
self.comboBox.move(200, 200)
self.resize(500, 500)
self.setStyleSheet('Demo{background:white}')
# setTheme(Theme.DARK)
if __name__ == '__main__':
......
......@@ -3,7 +3,7 @@ import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from qfluentwidgets import Dialog
from qfluentwidgets import Dialog, setTheme, Theme
class Window(QWidget):
......@@ -17,6 +17,8 @@ class Window(QWidget):
with open('resource/demo.qss', encoding='utf-8') as f:
self.setStyleSheet(f.read())
# setTheme(Theme.DARK)
def showDialog(self):
title = 'Are you sure you want to delete the folder?'
content = """If you delete the "Music" folder from the list, the folder will no longer appear in the list, but will not be deleted."""
......
......@@ -3,7 +3,7 @@ import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from qfluentwidgets import FolderListDialog
from qfluentwidgets import FolderListDialog, setTheme, Theme
class Window(QWidget):
......@@ -18,6 +18,8 @@ class Window(QWidget):
with open('resource/demo.qss', encoding='utf-8') as f:
self.setStyleSheet(f.read())
# setTheme(Theme.DARK)
def showDialog(self):
folder_paths = ['D:/KuGou', 'C:/Users/shoko/Documents/Music']
title = 'Build your collection from your local music files'
......
......@@ -2,8 +2,8 @@
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QAction, QHBoxLayout, QLabel
from qfluentwidgets import RoundMenu
from qfluentwidgets import FluentIconFactory as FIF
from qfluentwidgets import RoundMenu, setTheme, Theme
from qfluentwidgets import FluentIcon as FIF
class Demo(QWidget):
......@@ -18,26 +18,28 @@ class Demo(QWidget):
self.setStyleSheet('Demo{background: white} QLabel{font-size: 20px}')
# setTheme(Theme.DARK)
def contextMenuEvent(self, e):
menu = RoundMenu(parent=self)
# add actions
menu.addAction(QAction(FIF.icon(FIF.COPY), 'Copy'))
menu.addAction(QAction(FIF.icon(FIF.CUT), 'Cut'))
menu.addAction(QAction(FIF.COPY.icon(), 'Copy'))
menu.addAction(QAction(FIF.CUT.icon(), 'Cut'))
# add sub menu
submenu = RoundMenu("Add to", self)
submenu.setIcon(FIF.icon(FIF.ADD))
submenu.setIcon(FIF.ADD.icon())
submenu.addActions([
QAction(FIF.icon(FIF.VIDEO), 'Video'),
QAction(FIF.icon(FIF.MUSIC), 'Music'),
QAction(FIF.VIDEO.icon(), 'Video'),
QAction(FIF.MUSIC.icon(), 'Music'),
])
menu.addMenu(submenu)
# add actions
menu.addActions([
QAction(FIF.icon(FIF.PASTE), 'Paste'),
QAction(FIF.icon(FIF.CANCEL), 'Undo')
QAction(FIF.PASTE.icon(), 'Paste'),
QAction(FIF.CANCEL.icon(), 'Undo')
])
# add separator
......@@ -46,10 +48,10 @@ class Demo(QWidget):
# insert actions
menu.insertAction(
menu.menuActions()[-1], QAction(FIF.icon(FIF.SETTING), 'Settings'))
menu.menuActions()[-1], QAction(FIF.SETTING.icon(), 'Settings'))
menu.insertActions(
menu.menuActions()[-1],
[QAction(FIF.icon(FIF.HELP), 'Help'), QAction(FIF.icon(FIF.FEEDBACK), 'Feedback')]
[QAction(FIF.HELP.icon(), 'Help'), QAction(FIF.FEEDBACK.icon(), 'Feedback')]
)
# show menu
......
......@@ -3,7 +3,7 @@ import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from qfluentwidgets import MessageDialog, MessageBox
from qfluentwidgets import MessageDialog, MessageBox, setTheme, Theme
class Window(QWidget):
......@@ -17,6 +17,8 @@ class Window(QWidget):
with open('resource/demo.qss', encoding='utf-8') as f:
self.setStyleSheet(f.read())
# setTheme(Theme.DARK)
def showDialog(self):
title = 'Are you sure you want to delete the folder?'
content = """If you delete the "Music" folder from the list, the folder will no longer appear in the list, but will not be deleted."""
......
......@@ -4,9 +4,9 @@ from PyQt5.QtCore import Qt, QRect
from PyQt5.QtGui import QIcon, QPainter, QImage, QBrush, QColor, QFont
from PyQt5.QtWidgets import QApplication, QFrame, QStackedWidget, QHBoxLayout, QLabel
from qfluentwidgets import NavigationInterface, NavigationItemPostion, NavigationWidget, MessageBox
from qfluentwidgets import FluentIconFactory as FIF
from qfluentwidgets import (NavigationInterface, NavigationItemPostion, NavigationWidget, MessageBox,
isDarkTheme, setTheme, Theme)
from qfluentwidgets import FluentIcon as FIF
from qframelesswindow import FramelessWindow, StandardTitleBar
......@@ -40,14 +40,7 @@ class AvatarWidget(NavigationWidget):
painter.setOpacity(0.7)
# draw background
if self.isSelected:
painter.setBrush(QColor(0, 0, 0, 6 if self.isEnter else 10))
painter.drawRoundedRect(self.rect(), 5, 5)
# draw indicator
painter.setBrush(QColor(0, 153, 188))
painter.drawRoundedRect(0, 10, 3, 16, 1.5, 1.5)
elif self.isEnter:
if self.isEnter:
painter.setBrush(QColor(0, 0, 0, 10))
painter.drawRoundedRect(self.rect(), 5, 5)
......@@ -58,7 +51,7 @@ class AvatarWidget(NavigationWidget):
painter.translate(-8, -6)
if not self.isCompacted:
painter.setPen(Qt.black)
painter.setPen(Qt.white if isDarkTheme() else Qt.black)
font = QFont('Segoe UI')
font.setPixelSize(14)
painter.setFont(font)
......@@ -71,8 +64,11 @@ class Window(FramelessWindow):
super().__init__()
self.setTitleBar(StandardTitleBar(self))
# use dark theme mode
setTheme(Theme.DARK)
self.hBoxLayout = QHBoxLayout(self)
self.navigationInterface = NavigationInterface(self, True)
self.navigationInterface = NavigationInterface(self, showMenuButton=True)
self.stackWidget = QStackedWidget(self)
# create sub interface
......@@ -89,28 +85,36 @@ class Window(FramelessWindow):
self.stackWidget.addWidget(self.settingInterface)
# initialize layout
self.initLayout()
# add items to navigation interface
self.initNavigation()
self.initWindow()
def initLayout(self):
self.hBoxLayout.setSpacing(0)
self.hBoxLayout.setContentsMargins(0, self.titleBar.height(), 0, 0)
self.hBoxLayout.addWidget(self.navigationInterface)
self.hBoxLayout.addWidget(self.stackWidget)
self.hBoxLayout.setStretchFactor(self.stackWidget, 1)
# add items to navigation interface
def initNavigation(self):
self.navigationInterface.addItem(
routeKey=self.searchInterface.objectName(),
iconPath=FIF.path(FIF.SEARCH),
icon=FIF.SEARCH,
text='Search',
onClick=lambda: self.switchTo(self.searchInterface)
)
self.navigationInterface.addItem(
routeKey=self.musicInterface.objectName(),
iconPath=FIF.path(FIF.MUSIC),
icon=FIF.MUSIC,
text='Music library',
onClick=lambda: self.switchTo(self.musicInterface)
)
self.navigationInterface.addItem(
routeKey=self.navigationInterface.objectName(),
iconPath=FIF.path(FIF.VIDEO),
icon=FIF.VIDEO,
text='Video library',
onClick=lambda: self.switchTo(self.videoInterface)
)
......@@ -120,7 +124,7 @@ class Window(FramelessWindow):
# add navigation items to scroll area
self.navigationInterface.addItem(
routeKey='folder',
iconPath=FIF.path(FIF.FOLDER),
icon=FIF.FOLDER,
text='Folder library',
onClick=lambda: self.switchTo(self.folderInterface),
position=NavigationItemPostion.SCROLL
......@@ -128,7 +132,7 @@ class Window(FramelessWindow):
# for i in range(1, 21):
# self.navigationInterface.addItem(
# f'folder{i}',
# FIF.path(FIF.FOLDER),
# FIF.FOLDER,
# f'Folder {i}',
# lambda: print('Folder clicked'),
# position=NavigationItemPostion.SCROLL
......@@ -144,7 +148,7 @@ class Window(FramelessWindow):
self.navigationInterface.addItem(
routeKey='setting',
iconPath=FIF.path(FIF.SETTING),
icon=FIF.SETTING,
text='Settings',
onClick=lambda: self.switchTo(self.settingInterface),
position=NavigationItemPostion.BOTTOM
......@@ -153,17 +157,23 @@ class Window(FramelessWindow):
self.stackWidget.currentChanged.connect(self.onCurrentInterfaceChanged)
self.stackWidget.setCurrentIndex(1)
with open('resource/demo.qss', encoding='utf-8') as f:
self.setStyleSheet(f.read())
def initWindow(self):
self.resize(900, 700)
self.setWindowIcon(QIcon('resource/logo.png'))
self.setWindowTitle('PyQt-Fluent-Widgets')
self.titleBar.setAttribute(Qt.WA_StyledBackground)
desktop = QApplication.desktop().availableGeometry()
w, h = desktop.width(), desktop.height()
self.move(w//2 - self.width()//2, h//2 - self.height()//2)
self.setQss()
def setQss(self):
color = 'dark' if isDarkTheme() else 'light'
with open(f'resource/{color}/demo.qss', encoding='utf-8') as f:
self.setStyleSheet(f.read())
def switchTo(self, widget):
self.stackWidget.setCurrentWidget(widget)
......
Widget > QLabel {
font: 24px 'Segoe UI', 'Microsoft YaHei';
}
Widget {
border: 1px solid rgb(229, 229, 229);
border-right: none;
border-bottom: none;
border-top-left-radius: 10px;
background-color: rgb(249, 249, 249);
}
Window {
background-color: rgb(243, 243, 243);
}
Window {
background-color: rgb(32, 32, 32);
}
StandardTitleBar {
background-color: rgb(32, 32, 32);
}
StandardTitleBar > QLabel,
Widget > QLabel {
color: white;
}
Widget {
border: 1px solid rgb(29, 29, 29);
background-color: rgb(39, 39, 39);
}
MinimizeButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: white;
qproperty-hoverBackgroundColor: rgba(255, 255, 255, 26);
qproperty-pressedColor: white;
qproperty-pressedBackgroundColor: rgba(255, 255, 255, 51)
}
MaximizeButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: white;
qproperty-hoverBackgroundColor: rgba(255, 255, 255, 26);
qproperty-pressedColor: white;
qproperty-pressedBackgroundColor: rgba(255, 255, 255, 51)
}
CloseButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
}
......@@ -12,4 +12,5 @@ Widget {
Window {
background-color: rgb(243, 243, 243);
}
\ No newline at end of file
}
# coding:utf-8
import os
import sys
from PyQt5.QtCore import Qt, QLocale, QTranslator
from PyQt5.QtGui import QIcon, QColor
from PyQt5.QtWidgets import QApplication, QLabel, QHBoxLayout
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QHBoxLayout
from qframelesswindow import FramelessWindow, TitleBar
from qframelesswindow.titlebar import TitleBarButton
from qframelesswindow import FramelessWindow, StandardTitleBar
from qfluentwidgets import isDarkTheme
from setting_interface import SettingInterface
from config import cfg, Language
class CustomTitleBar(TitleBar):
""" Custom title bar """
def __init__(self, parent):
super().__init__(parent)
# add window icon
self.iconLabel = QLabel(self)
self.iconLabel.setFixedSize(20, 20)
self.hBoxLayout.insertSpacing(0, 8)
self.hBoxLayout.insertWidget(1, self.iconLabel, 0, Qt.AlignLeft)
self.window().windowIconChanged.connect(self.setIcon)
# add title label
self.titleLabel = QLabel(self)
self.hBoxLayout.insertWidget(2, self.titleLabel, 0, Qt.AlignLeft)
self.titleLabel.setStyleSheet(f"""
QLabel{{
background: transparent;
font: 13px 'Segoe UI';
padding: 0 4px;
color: {'white' if isDarkTheme() else 'black'}
}}
""")
self.window().windowTitleChanged.connect(self.setTitle)
# customize title bar button
if isDarkTheme():
for button in (self.findChildren(TitleBarButton)):
button.setNormalColor(Qt.white)
button.setHoverColor(Qt.white)
button.setPressedColor(Qt.white)
if button is not self.closeBtn:
button.setHoverBackgroundColor(QColor(255, 255, 255, 26))
button.setPressedBackgroundColor(QColor(255, 255, 255, 51))
def setTitle(self, title):
self.titleLabel.setText(title)
self.titleLabel.adjustSize()
def setIcon(self, icon):
self.iconLabel.setPixmap(icon.pixmap(20, 20))
class Window(FramelessWindow):
def __init__(self, parent=None):
super().__init__(parent=parent)
# change the default title bar if you like
self.setTitleBar(CustomTitleBar(self))
self.setTitleBar(StandardTitleBar(self))
self.hBoxLayout = QHBoxLayout(self)
self.settingInterface = SettingInterface(self)
......@@ -77,6 +34,14 @@ class Window(FramelessWindow):
self.titleBar.raise_()
self.setQss()
cfg.themeChanged.connect(self.setQss)
def setQss(self):
theme = 'dark' if isDarkTheme() else 'light'
with open(f'resource/qss/{theme}/demo.qss', encoding='utf-8') as f:
self.setStyleSheet(f.read())
if __name__ == '__main__':
# enable dpi scale
......
MinimizeButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: white;
qproperty-hoverBackgroundColor: rgba(255, 255, 255, 26);
qproperty-pressedColor: white;
qproperty-pressedBackgroundColor: rgba(255, 255, 255, 51)
}
MaximizeButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: white;
qproperty-hoverBackgroundColor: rgba(255, 255, 255, 26);
qproperty-pressedColor: white;
qproperty-pressedBackgroundColor: rgba(255, 255, 255, 51)
}
CloseButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
}
StandardTitleBar > QLabel {
color: white;
}
\ No newline at end of file
MinimizeButton {
qproperty-normalColor: black;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: black;
qproperty-hoverBackgroundColor: rgba(0, 0, 0, 26);
qproperty-pressedColor: black;
qproperty-pressedBackgroundColor: rgba(0, 0, 0, 51)
}
MaximizeButton {
qproperty-normalColor: black;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: black;
qproperty-hoverBackgroundColor: rgba(0, 0, 0, 26);
qproperty-pressedColor: black;
qproperty-pressedBackgroundColor: rgba(0, 0, 0, 51)
}
CloseButton {
qproperty-normalColor: black;
qproperty-normalBackgroundColor: transparent;
}
\ No newline at end of file
......@@ -3,8 +3,8 @@ from config import cfg, HELP_URL, FEEDBACK_URL, AUTHOR, VERSION, YEAR
from qfluentwidgets import (SettingCardGroup, SwitchSettingCard, FolderListSettingCard,
OptionsSettingCard, RangeSettingCard, PushSettingCard,
ColorSettingCard, HyperlinkCard, PrimaryPushSettingCard, ScrollArea,
ComboBoxSettingCard, ExpandLayout, setStyleSheet, ToastToolTip)
from qfluentwidgets import FluentIconFactory as FIF
ComboBoxSettingCard, ExpandLayout, setStyleSheet, ToastToolTip, setTheme)
from qfluentwidgets import FluentIcon as FIF
from PyQt5.QtCore import Qt, pyqtSignal, QUrl, QStandardPaths
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtWidgets import QWidget, QLabel, QFontDialog, QFileDialog
......@@ -38,7 +38,7 @@ class SettingInterface(ScrollArea):
)
self.downloadFolderCard = PushSettingCard(
self.tr('Choose folder'),
FIF.path(FIF.DOWNLOAD),
FIF.DOWNLOAD,
self.tr("Download directory"),
cfg.get(cfg.downloadFolder),
self.musicInThisPCGroup
......@@ -47,7 +47,7 @@ class SettingInterface(ScrollArea):
# personalization
self.personalGroup = SettingCardGroup(self.tr('Personalization'), self.scrollWidget)
self.enableAcrylicCard = SwitchSettingCard(
FIF.path(FIF.TRANSPARENT),
FIF.TRANSPARENT,
self.tr("Use Acrylic effect"),
self.tr("Acrylic effect has better visual experience, but it may cause the window to become stuck"),
configItem=cfg.enableAcrylicBackground,
......@@ -55,7 +55,7 @@ class SettingInterface(ScrollArea):
)
self.themeCard = OptionsSettingCard(
cfg.themeMode,
FIF.path(FIF.BRUSH),
FIF.BRUSH,
self.tr('Application theme'),
self.tr("Change the appearance of your application"),
texts=[
......@@ -66,7 +66,7 @@ class SettingInterface(ScrollArea):
)
self.zoomCard = OptionsSettingCard(
cfg.dpiScale,
FIF.path(FIF.ZOOM),
FIF.ZOOM,
self.tr("Interface zoom"),
self.tr("Change the size of widgets and fonts"),
texts=[
......@@ -77,7 +77,7 @@ class SettingInterface(ScrollArea):
)
self.languageCard = ComboBoxSettingCard(
cfg.language,
FIF.path(FIF.LANGUAGE),
FIF.LANGUAGE,
self.tr('Language'),
self.tr('Set your preferred language for UI'),
texts=['简体中文', '繁體中文', 'English', self.tr('Use system setting')],
......@@ -88,13 +88,13 @@ class SettingInterface(ScrollArea):
self.onlineMusicGroup = SettingCardGroup(self.tr('Online Music'), self.scrollWidget)
self.onlinePageSizeCard = RangeSettingCard(
cfg.onlinePageSize,
FIF.path(FIF.SEARCH),
FIF.SEARCH,
self.tr("Number of online music displayed on each page"),
parent=self.onlineMusicGroup
)
self.onlineMusicQualityCard = OptionsSettingCard(
cfg.onlineSongQuality,
FIF.path(FIF.MUSIC),
FIF.MUSIC,
self.tr('Online music quality'),
texts=[
self.tr('Standard quality'), self.tr('High quality'),
......@@ -104,7 +104,7 @@ class SettingInterface(ScrollArea):
)
self.onlineMvQualityCard = OptionsSettingCard(
cfg.onlineMvQuality,
FIF.path(FIF.VIDEO),
FIF.VIDEO,
self.tr('Online MV quality'),
texts=[
self.tr('Full HD'), self.tr('HD'),
......@@ -117,31 +117,31 @@ class SettingInterface(ScrollArea):
self.deskLyricGroup = SettingCardGroup(self.tr('Desktop Lyric'), self.scrollWidget)
self.deskLyricFontCard = PushSettingCard(
self.tr('Choose font'),
FIF.path(FIF.FONT),
FIF.FONT,
self.tr('Font'),
parent=self.deskLyricGroup
)
self.deskLyricHighlightColorCard = ColorSettingCard(
cfg.deskLyricHighlightColor,
FIF.path(FIF.PALETTE),
FIF.PALETTE,
self.tr('Foreground color'),
parent=self.deskLyricGroup
)
self.deskLyricStrokeColorCard = ColorSettingCard(
cfg.deskLyricStrokeColor,
FIF.path(FIF.PENCIL_INK),
FIF.PENCIL_INK,
self.tr('Stroke color'),
parent=self.deskLyricGroup
)
self.deskLyricStrokeSizeCard = RangeSettingCard(
cfg.deskLyricStrokeSize,
FIF.path(FIF.FLUORESCENT_PEN),
FIF.FLUORESCENT_PEN,
self.tr('Stroke size'),
parent=self.deskLyricGroup
)
self.deskLyricAlignmentCard = OptionsSettingCard(
cfg.deskLyricAlignment,
FIF.path(FIF.ALIGNMENT),
FIF.ALIGNMENT,
self.tr('Alignment'),
texts=[
self.tr('Center aligned'), self.tr('Left aligned'),
......@@ -153,7 +153,7 @@ class SettingInterface(ScrollArea):
# main panel
self.mainPanelGroup = SettingCardGroup(self.tr('Main Panel'), self.scrollWidget)
self.minimizeToTrayCard = SwitchSettingCard(
FIF.path(FIF.MINIMIZE),
FIF.MINIMIZE,
self.tr('Minimize to tray after closing'),
self.tr('PyQt-Fluent-Widgets will continue to run in the background'),
configItem=cfg.minimizeToTray,
......@@ -163,7 +163,7 @@ class SettingInterface(ScrollArea):
# update software
self.updateSoftwareGroup = SettingCardGroup(self.tr("Software update"), self.scrollWidget)
self.updateOnStartUpCard = SwitchSettingCard(
FIF.path(FIF.UPDATE),
FIF.UPDATE,
self.tr('Check for updates when the application starts'),
self.tr('The new version will be more stable and have more features'),
configItem=cfg.checkUpdateAtStartUp,
......@@ -175,21 +175,21 @@ class SettingInterface(ScrollArea):
self.helpCard = HyperlinkCard(
HELP_URL,
self.tr('Open help page'),
FIF.path(FIF.HELP),
FIF.HELP,
self.tr('Help'),
self.tr('Discover new features and learn useful tips about PyQt-Fluent-Widgets'),
self.aboutGroup
)
self.feedbackCard = PrimaryPushSettingCard(
self.tr('Provide feedback'),
FIF.path(FIF.FEEDBACK),
FIF.FEEDBACK,
self.tr('Provide feedback'),
self.tr('Help us improve PyQt-Fluent-Widgets by providing feedback'),
self.aboutGroup
)
self.aboutCard = PrimaryPushSettingCard(
self.tr('Check update'),
FIF.path(FIF.INFO),
FIF.INFO,
self.tr('About'),
'© ' + self.tr('Copyright') + f" {YEAR}, {AUTHOR}. " +
self.tr('Version') + f" {VERSION[1:]}",
......@@ -283,6 +283,7 @@ class SettingInterface(ScrollArea):
def __connectSignalToSlot(self):
""" connect signal to slot """
cfg.appRestartSig.connect(self.__showRestartTooltip)
cfg.themeChanged.connect(setTheme)
# music in the pc
self.musicFolderCard.folderChanged.connect(
......
from .config import *
from .auto_wrap import TextWrap
from .icon import Icon, getIconColor, drawSvgIcon, FluentIconFactory, drawIcon
from .style_sheet import setStyleSheet, getStyleSheet
from .icon import Icon, getIconColor, drawSvgIcon, FluentIcon, drawIcon
from .style_sheet import setStyleSheet, getStyleSheet, setTheme
from .smooth_scroll import SmoothScroll, SmoothMode
\ No newline at end of file
......@@ -2,11 +2,12 @@
import json
from enum import Enum
from pathlib import Path
from typing import Iterable, List, Union
from typing import List
import darkdetect
from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import qApp
from .exception_handler import exceptionHandler
......@@ -249,9 +250,10 @@ class QConfig(QObject):
""" Config of app """
appRestartSig = pyqtSignal()
themeChanged = pyqtSignal(Theme)
themeMode = OptionsConfigItem(
"MainWindow", "ThemeMode", Theme.AUTO, OptionsValidator(Theme), EnumSerializer(Theme), restart=True)
"MainWindow", "ThemeMode", Theme.AUTO, OptionsValidator(Theme), EnumSerializer(Theme))
def __init__(self):
super().__init__()
......@@ -274,6 +276,9 @@ class QConfig(QObject):
if item.restart:
self._cfg.appRestartSig.emit()
if item is self._cfg.themeMode:
self._cfg.themeChanged.emit(value)
def toDict(self, serialize=True):
""" convert config items to `dict` """
items = {}
......@@ -354,6 +359,15 @@ class QConfig(QObject):
""" get theme mode, can be `Theme.Light` or `Theme.Dark` """
return self._cfg._theme
@theme.setter
def theme(self, t):
""" chaneg the theme without modifying the config file """
if t == Theme.AUTO:
t = darkdetect.theme()
t = Theme(t) if t else Theme.LIGHT
self._cfg._theme = t
qconfig = QConfig()
......
# coding:utf-8
from enum import Enum
from PyQt5.QtCore import QPoint, QRect, QRectF, Qt
from PyQt5.QtGui import QIcon, QIconEngine, QImage, QPainter, QPixmap
from PyQt5.QtSvg import QSvgRenderer
from .config import isDarkTheme
from .config import isDarkTheme, Theme
class IconEngine(QIconEngine):
......@@ -68,13 +70,13 @@ def drawSvgIcon(iconPath, painter, rect):
renderer.render(painter, QRectF(rect))
def drawIcon(iconPath, painter, rect):
def drawIcon(icon, painter:QPainter, rect):
""" draw icon
Parameters
----------
iconPath: str
the path of svg icon
icon: `str` | `QIcon` | `FluentIcon`
the icon to be drawn
painter: QPainter
painter
......@@ -82,16 +84,16 @@ def drawIcon(iconPath, painter, rect):
rect: QRect | QRectF
the rect to render icon
"""
if not iconPath.lower().endswith('svg'):
image = QImage(iconPath).scaled(
rect.width(), rect.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
painter.drawImage(rect, image)
if isinstance(icon, FluentIcon):
icon.render(painter, rect)
else:
drawSvgIcon(iconPath, painter, rect)
icon = QIcon(icon)
image = icon.pixmap(rect.width(), rect.height())
painter.drawPixmap(rect, image)
class FluentIconFactory:
""" Fluent icon factory """
class FluentIcon(Enum):
""" Fluent icon """
WEB = "Web"
CUT = "Cut"
......@@ -131,29 +133,52 @@ class FluentIconFactory:
BACKGROUND_FILL = "BackgroundColor"
FLUORESCENT_PEN = "FluorescentPen"
@staticmethod
def path(iconType):
""" get the path of icon """
return f':/qfluentwidgets/images/icons/{iconType}_{getIconColor()}.svg'
def path(self, theme=Theme.AUTO):
""" get the path of icon
@classmethod
def icon(cls, iconType):
""" create an fluent icon """
return QIcon(cls.path(iconType))
Parameters
----------
theme: Theme
the theme of icon
* `Theme.Light`: black icon
* `Theme.DARK`: white icon
* `Theme.AUTO`: icon color depends on `config.theme`
"""
if theme == Theme.AUTO:
c = getIconColor()
else:
c = "white" if theme == Theme.DARK else "black"
@classmethod
def render(cls, iconType, painter, rect):
""" draw svg icon
return f':/qfluentwidgets/images/icons/{self.value}_{c}.svg'
def icon(self, theme=Theme.AUTO):
""" create an fluent icon
Parameters
----------
iconType: str
fluent icon type
theme: Theme
the theme of icon
* `Theme.Light`: black icon
* `Theme.DARK`: white icon
* `Theme.AUTO`: icon color depends on `config.theme`
"""
return QIcon(self.path(theme))
def render(self, painter, rect, theme=Theme.AUTO):
""" draw svg icon
Parameters
----------
painter: QPainter
painter
rect: QRect | QRectF
the rect to render icon
theme: Theme
the theme of icon
* `Theme.Light`: black icon
* `Theme.DARK`: white icon
* `Theme.AUTO`: icon color depends on `config.theme`
"""
drawSvgIcon(cls.path(iconType), painter, rect)
\ No newline at end of file
drawSvgIcon(self.path(theme), painter, rect)
\ No newline at end of file
......@@ -5,7 +5,7 @@ from math import cos, pi
from PyQt5.QtCore import QDateTime, Qt, QTimer, QPoint
from PyQt5.QtGui import QWheelEvent
from PyQt5.QtWidgets import QApplication, QScrollArea
from PyQt5.QtWidgets import QApplication, QScrollArea, QAbstractScrollArea
class SmoothScroll:
......@@ -41,7 +41,7 @@ class SmoothScroll:
def wheelEvent(self, e):
if self.smoothMode == SmoothMode.NO_SMOOTH:
self.widget.wheelEvent(e)
QAbstractScrollArea.wheelEvent(self.widget, e)
return
# push current time to queque
......
# coding:utf-8
from .config import qconfig, Theme
import weakref
import darkdetect
from PyQt5.QtCore import QFile
from .config import qconfig, Theme
fluentWidgets = weakref.WeakKeyDictionary()
def getStyleSheet(file, theme=Theme.AUTO):
""" get style sheet
......@@ -36,4 +43,20 @@ def setStyleSheet(widget, file, theme=Theme.AUTO):
theme: Theme
the theme of style sheet
"""
widget.setStyleSheet(getStyleSheet(file, theme))
\ No newline at end of file
# register widget
if widget not in fluentWidgets:
fluentWidgets[widget] = file
widget.setStyleSheet(getStyleSheet(file, theme))
def setTheme(theme: Theme):
""" set the theme of application """
if theme == Theme.AUTO:
theme = darkdetect.theme()
qconfig.theme = Theme(theme) if theme else Theme.LIGHT
else:
qconfig.theme = theme
for widget, file in fluentWidgets.items():
setStyleSheet(widget, file, qconfig.theme)
\ No newline at end of file
# coding:utf-8
from PyQt5.QtCore import Qt, pyqtSignal, QEvent
from PyQt5.QtGui import QResizeEvent
from typing import Union
from PyQt5.QtCore import Qt, QEvent
from PyQt5.QtGui import QResizeEvent, QIcon
from PyQt5.QtWidgets import QWidget
from .navigation_panel import NavigationPanel, NavigationItemPostion, NavigationWidget, NavigationDisplayMode
from ...common.style_sheet import setStyleSheet
from ...common.icon import FluentIcon
class NavigationInterface(QWidget):
......@@ -30,7 +33,7 @@ class NavigationInterface(QWidget):
self.setAttribute(Qt.WA_StyledBackground)
setStyleSheet(self, 'navigation_interface')
def addItem(self, routeKey: str, iconPath: str, text: str, onClick, selectable=True, position=NavigationItemPostion.TOP):
def addItem(self, routeKey: str, icon: Union[str, QIcon, FluentIcon], text: str, onClick, selectable=True, position=NavigationItemPostion.TOP):
""" add navigation item
Parameters
......@@ -38,8 +41,8 @@ class NavigationInterface(QWidget):
routKey: str
the unique name of item
iconPath: str
the svg icon path of navigation item
icon: str | QIcon | FluentIcon
the icon of navigation item
text: str
the text of navigation item
......@@ -53,7 +56,7 @@ class NavigationInterface(QWidget):
selectable: bool
whether the item is selectable
"""
self.panel.addItem(routeKey, iconPath, text, onClick, selectable, position)
self.panel.addItem(routeKey, icon, text, onClick, selectable, position)
def addWidget(self, routeKey: str, widget: NavigationWidget, onClick, position=NavigationItemPostion.TOP):
""" add custom widget
......
# coding:utf-8
from enum import Enum
from typing import Dict
from typing import Dict, Union
from PyQt5.QtCore import Qt, QPropertyAnimation, QRect, QSize, QEvent, QEasingCurve
from PyQt5.QtGui import QResizeEvent
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QFrame, QApplication
from PyQt5.QtGui import QResizeEvent, QIcon
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QFrame
from .navigation_widget import NavigationButton, MenuButton, NavigationWidget, NavigationSeparator
from ..widgets.scroll_area import ScrollArea
from ...common.style_sheet import setStyleSheet, getStyleSheet
from ...common.icon import FluentIcon
class NavigationDisplayMode(Enum):
......@@ -95,7 +96,7 @@ class NavigationPanel(QFrame):
self.topLayout.addWidget(self.menuButton, 0, Qt.AlignTop)
def addItem(self, routeKey: str, iconPath: str, text: str, onClick, selectable=True, position=NavigationItemPostion.TOP):
def addItem(self, routeKey: str, icon: Union[str, QIcon, FluentIcon], text: str, onClick, selectable=True, position=NavigationItemPostion.TOP):
""" add navigation item
Parameters
......@@ -103,8 +104,8 @@ class NavigationPanel(QFrame):
routeKey: str
the unique name of item
iconPath: str
the svg icon path of navigation item
icon: str | QIcon | FluentIcon
the icon of navigation item
text: str
the text of navigation item
......@@ -121,7 +122,7 @@ class NavigationPanel(QFrame):
if text in self.items:
return
button = NavigationButton(iconPath, text, selectable, self)
button = NavigationButton(icon, text, selectable, self)
self.addWidget(routeKey, button, onClick, position)
def addWidget(self, routeKey: str, widget: NavigationWidget, onClick, position=NavigationItemPostion.TOP):
......@@ -266,6 +267,9 @@ class NavigationPanel(QFrame):
w = QResizeEvent(e).size().width()
if w < 1008 and self.displayMode == NavigationDisplayMode.EXPAND:
self.collapse()
elif w >= 1008 and self.displayMode == NavigationDisplayMode.COMPACT and \
not self.menuButton.isVisible():
self.expand()
return super().eventFilter(obj, e)
......
# coding:utf-8
from typing import Union
from PyQt5.QtCore import Qt, pyqtSignal, QRect, QRectF
from PyQt5.QtGui import QColor, QPainter, QPen
from PyQt5.QtGui import QColor, QPainter, QPen, QIcon
from PyQt5.QtWidgets import QWidget
from ...common.config import isDarkTheme
from ...common.icon import drawIcon
from ...common.icon import FluentIconFactory as FIF
from ...common.icon import FluentIcon as FIF
class NavigationWidget(QWidget):
......@@ -71,19 +73,19 @@ class NavigationWidget(QWidget):
class NavigationButton(NavigationWidget):
""" Navigation button """
def __init__(self, iconPath: str, text: str, isSelectable: bool, parent=None):
def __init__(self, icon: Union[str, QIcon, FIF], text: str, isSelectable: bool, parent=None):
"""
Parameters
----------
iconPath: str
the path of button icon
icon: str | QIcon | FluentIcon
the icon to be drawn
text: str
the text of button
"""
super().__init__(isSelectable=isSelectable, parent=parent)
self.iconPath = iconPath
self.icon = icon
self._text = text
self.setStyleSheet(
......@@ -108,13 +110,14 @@ class NavigationButton(NavigationWidget):
painter.drawRoundedRect(self.rect(), 5, 5)
# draw indicator
painter.setBrush(QColor(0, 153, 188))
color = QColor(41, 247, 255) if isDarkTheme() else QColor(0, 153, 188)
painter.setBrush(color)
painter.drawRoundedRect(0, 10, 3, 16, 1.5, 1.5)
elif self.isEnter:
painter.setBrush(QColor(c, c, c, 10))
painter.drawRoundedRect(self.rect(), 5, 5)
drawIcon(self.iconPath, painter, QRectF(11.5, 10, 16, 16))
drawIcon(self.icon, painter, QRectF(11.5, 10, 16, 16))
# draw text
if not self.isCompacted:
......@@ -128,7 +131,7 @@ class MenuButton(NavigationButton):
""" Menu button """
def __init__(self, parent=None):
super().__init__(FIF.path(FIF.MENU), '', parent)
super().__init__(FIF.MENU, '', parent)
def setCompacted(self, isCompacted: bool):
self.setFixedSize(40, 36)
......
# coding:utf-8
from typing import Union
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import (QEvent, Qt, QPropertyAnimation, pyqtProperty, QEasingCurve,
QParallelAnimationGroup, QRect, QSize, QPoint, QRectF)
from PyQt5.QtGui import QColor, QPainter
from PyQt5.QtWidgets import QFrame, QWidget, QAbstractButton, QApplication
from ...common.config import isDarkTheme
from ...common.icon import FluentIconFactory as FIF
from ...common.icon import FluentIcon as FIF
from ...common.style_sheet import setStyleSheet
from .setting_card import SettingCard
from ..layout.v_box_layout import VBoxLayout
......@@ -44,7 +46,7 @@ class ExpandButton(QAbstractButton):
# draw icon
painter.translate(self.width()//2, self.height()//2)
painter.rotate(self.__angle)
FIF.render(FIF.ARROW_DOWN, painter, QRectF(-6, -6, 9.6, 9.6))
FIF.ARROW_DOWN.render(painter, QRectF(-6, -6, 9.6, 9.6))
def enterEvent(self, e):
self.setHover(True)
......@@ -86,12 +88,12 @@ class ExpandButton(QAbstractButton):
class ExpandSettingCard(QFrame):
""" Expandable setting card """
def __init__(self, iconPath: str, title: str, content: str = None, parent=None):
def __init__(self, icon: Union[str, QIcon, FIF], title: str, content: str = None, parent=None):
super().__init__(parent=parent)
self.isExpand = False
self.expandButton = ExpandButton(self)
self.view = QFrame(self)
self.card = SettingCard(iconPath, title, content, self)
self.card = SettingCard(icon, title, content, self)
self.viewLayout = VBoxLayout(self.view)
# expand animation
......
......@@ -3,13 +3,13 @@ from typing import List
from pathlib import Path
from PyQt5.QtCore import Qt, pyqtSignal, QRectF
from PyQt5.QtGui import QPainter
from PyQt5.QtGui import QPainter, QIcon
from PyQt5.QtWidgets import (QPushButton, QFileDialog, QWidget, QLabel,
QHBoxLayout, QToolButton)
from ...common.config import ConfigItem, qconfig
from ...common.icon import drawSvgIcon
from ...common.icon import FluentIconFactory as FIF
from ...common.icon import drawIcon
from ...common.icon import FluentIcon as FIF
from ..dialog_box.dialog import Dialog
from .expand_setting_card import ExpandSettingCard
......@@ -17,10 +17,10 @@ from .expand_setting_card import ExpandSettingCard
class ToolButton(QToolButton):
""" Tool button """
def __init__(self, iconPath: str, size: tuple, iconSize: tuple, parent=None):
def __init__(self, icon, size: tuple, iconSize: tuple, parent=None):
super().__init__(parent=parent)
self.isPressed = False
self.iconPath = iconPath
self._icon = icon
self._iconSize = iconSize
self.setFixedSize(*size)
......@@ -39,17 +39,17 @@ class ToolButton(QToolButton):
QPainter.SmoothPixmapTransform)
painter.setOpacity(0.63 if self.isPressed else 1)
w, h = self._iconSize
drawSvgIcon(self.iconPath, painter, QRectF(
drawIcon(self._icon, painter, QRectF(
(self.width()-w)//2, (self.height()-h)//2, w, h))
class PushButton(QPushButton):
""" Push button """
def __init__(self, iconPath: str, text: str, parent=None):
def __init__(self, icon, text: str, parent=None):
super().__init__(parent=parent)
self.isPressed = False
self.iconPath = iconPath
self._icon = icon
self.setText(text)
def mousePressEvent(self, e):
......@@ -65,7 +65,7 @@ class PushButton(QPushButton):
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing)
painter.setOpacity(0.63 if self.isPressed else 1)
drawSvgIcon(self.iconPath, painter, QRectF(12, 8, 16, 16))
drawIcon(self._icon, painter, QRectF(12, 8, 16, 16))
class FolderItem(QWidget):
......@@ -78,7 +78,7 @@ class FolderItem(QWidget):
self.folder = folder
self.hBoxLayout = QHBoxLayout(self)
self.folderLabel = QLabel(folder, self)
self.removeButton = ToolButton(FIF.path(FIF.CLOSE), (39, 29), (12, 12), self)
self.removeButton = ToolButton(FIF.CLOSE, (39, 29), (12, 12), self)
self.setFixedHeight(53)
self.hBoxLayout.setContentsMargins(48, 0, 60, 0)
......@@ -116,11 +116,10 @@ class FolderListSettingCard(ExpandSettingCard):
parent: QWidget
parent widget
"""
super().__init__(FIF.path(FIF.FOLDER), title, content, parent)
super().__init__(FIF.FOLDER, title, content, parent)
self.configItem = configItem
self._dialogDirectory = directory
self.addFolderButton = PushButton(
FIF.path(FIF.FOLDER_ADD), self.tr('Add folder'), self)
self.addFolderButton = PushButton(FIF.FOLDER_ADD, self.tr('Add folder'), self)
self.folders = qconfig.get(configItem).copy() # type:List[str]
self.__initWidget()
......
# coding:utf-8
from typing import List
from typing import Union
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QButtonGroup, QLabel, QRadioButton
from ...common.config import OptionsConfigItem, qconfig
from ...common.icon import FluentIcon
from .expand_setting_card import ExpandSettingCard
......@@ -12,15 +14,15 @@ class OptionsSettingCard(ExpandSettingCard):
optionChanged = pyqtSignal(OptionsConfigItem)
def __init__(self, configItem, iconPath, title, content=None, texts=None, parent=None):
def __init__(self, configItem, icon: Union[str, QIcon, FluentIcon], title, content=None, texts=None, parent=None):
"""
Parameters
----------
configItem: OptionsConfigItem
options config item
iconPath: str
icon path
icon: str | QIcon | FluentIcon
the icon to be drawn
title: str
the title of setting card
......@@ -34,7 +36,7 @@ class OptionsSettingCard(ExpandSettingCard):
parent: QWidget
parent window
"""
super().__init__(iconPath, title, content, parent)
super().__init__(icon, title, content, parent)
self.texts = texts or []
self.configItem = configItem
self.configName = configItem.name
......
# coding:utf-8
from typing import Union
from PyQt5.QtCore import QUrl, Qt, pyqtSignal
from PyQt5.QtGui import QColor, QDesktopServices
from PyQt5.QtGui import QColor, QDesktopServices, QIcon
from PyQt5.QtWidgets import (QFrame, QHBoxLayout, QLabel, QToolButton,
QVBoxLayout, QPushButton)
from PyQt5.QtSvg import QSvgWidget
from ..dialog_box.color_dialog import ColorDialog
from ..widgets.combo_box import ComboBox
from ..widgets.switch_button import SwitchButton, IndicatorPosition
from ..widgets.slider import Slider
from ..widgets.icon_widget import IconWidget
from ...common.style_sheet import setStyleSheet, getStyleSheet
from ...common.config import qconfig, OptionsConfigItem
from ...common.config import qconfig
from ...common.icon import FluentIcon
class SettingCard(QFrame):
""" Setting card """
def __init__(self, iconPath, title, content=None, parent=None):
def __init__(self, icon: Union[str, QIcon, FluentIcon], title, content=None, parent=None):
"""
Parameters
----------
iconPath: str
the path of svg icon
icon: str | QIcon | FluentIcon
the icon to be drawn
title: str
the title of card
......@@ -33,7 +36,7 @@ class SettingCard(QFrame):
parent widget
"""
super().__init__(parent=parent)
self.iconLabel = QSvgWidget(iconPath, self)
self.iconLabel = IconWidget(icon, self)
self.titleLabel = QLabel(title, self)
self.contentLabel = QLabel(content or '', self)
self.hBoxLayout = QHBoxLayout(self)
......@@ -81,12 +84,12 @@ class SwitchSettingCard(SettingCard):
checkedChanged = pyqtSignal(bool)
def __init__(self, iconPath, title, content=None, configItem=None, parent=None):
def __init__(self, icon: Union[str, QIcon, FluentIcon], title, content=None, configItem=None, parent=None):
"""
Parameters
----------
iconPath: str
the path of icon
icon: str | QIcon | FluentIcon
the icon to be drawn
title: str
the title of card
......@@ -100,7 +103,7 @@ class SwitchSettingCard(SettingCard):
parent: QWidget
parent widget
"""
super().__init__(iconPath, title, content, parent)
super().__init__(icon, title, content, parent)
self.configItem = configItem
self.switchButton = SwitchButton(
self.tr('Off'), self, IndicatorPosition.RIGHT)
......@@ -139,15 +142,15 @@ class RangeSettingCard(SettingCard):
valueChanged = pyqtSignal(int)
def __init__(self, configItem, iconPath, title, content=None, parent=None):
def __init__(self, configItem, icon: Union[str, QIcon, FluentIcon], title, content=None, parent=None):
"""
Parameters
----------
configItem: RangeConfigItem
configuration item operated by the card
iconPath: str
the path of icon
icon: str | QIcon | FluentIcon
the icon to be drawn
title: str
the title of card
......@@ -158,7 +161,7 @@ class RangeSettingCard(SettingCard):
parent: QWidget
parent widget
"""
super().__init__(iconPath, title, content, parent)
super().__init__(icon, title, content, parent)
self.configItem = configItem
self.slider = Slider(Qt.Horizontal, self)
self.valueLabel = QLabel(self)
......@@ -190,15 +193,15 @@ class PushSettingCard(SettingCard):
clicked = pyqtSignal()
def __init__(self, text, iconPath, title, content=None, parent=None):
def __init__(self, text, icon: Union[str, QIcon, FluentIcon], title, content=None, parent=None):
"""
Parameters
----------
text: str
the text of push button
iconPath: str
the path of icon
icon: str | QIcon | FluentIcon
the icon to be drawn
title: str
the title of card
......@@ -209,7 +212,7 @@ class PushSettingCard(SettingCard):
parent: QWidget
parent widget
"""
super().__init__(iconPath, title, content, parent)
super().__init__(icon, title, content, parent)
self.button = QPushButton(text, self)
self.hBoxLayout.addWidget(self.button, 0, Qt.AlignRight)
self.hBoxLayout.addSpacing(16)
......@@ -219,15 +222,15 @@ class PushSettingCard(SettingCard):
class PrimaryPushSettingCard(PushSettingCard):
""" Push setting card with primary color """
def __init__(self, text, iconPath, title, content=None, parent=None):
super().__init__(text, iconPath, title, content, parent)
def __init__(self, text, icon, title, content=None, parent=None):
super().__init__(text, icon, title, content, parent)
self.button.setObjectName('primaryButton')
class HyperlinkCard(SettingCard):
""" Hyperlink card """
def __init__(self, url, text, iconPath, title, content=None, parent=None):
def __init__(self, url, text, icon: Union[str, QIcon, FluentIcon], title, content=None, parent=None):
"""
Parameters
----------
......@@ -237,8 +240,8 @@ class HyperlinkCard(SettingCard):
text: str
text of url
iconPath: str
the path of icon
icon: str | QIcon | FluentIcon
the icon to be drawn
title: str
the title of card
......@@ -252,7 +255,7 @@ class HyperlinkCard(SettingCard):
parent: QWidget
parent widget
"""
super().__init__(iconPath, title, content, parent)
super().__init__(icon, title, content, parent)
self.url = QUrl(url)
self.linkButton = QPushButton(text, self)
......@@ -307,15 +310,15 @@ class ColorSettingCard(SettingCard):
colorChanged = pyqtSignal(QColor)
def __init__(self, configItem, iconPath, title, content=None, parent=None):
def __init__(self, configItem, icon: Union[str, QIcon, FluentIcon], title, content=None, parent=None):
"""
Parameters
----------
configItem: RangeConfigItem
configuration item operated by the card
iconPath: str
the path of icon
icon: str | QIcon | FluentIcon
the icon to be drawn
title: str
the title of card
......@@ -326,7 +329,7 @@ class ColorSettingCard(SettingCard):
parent: QWidget
parent widget
"""
super().__init__(iconPath, title, content, parent)
super().__init__(icon, title, content, parent)
self.configItem = configItem
self.colorPicker = ColorPickerButton(
qconfig.get(configItem), title, self)
......@@ -342,15 +345,15 @@ class ColorSettingCard(SettingCard):
class ComboBoxSettingCard(SettingCard):
""" Setting card with a combo box """
def __init__(self, configItem, iconPath, title, content=None, texts=None, parent=None):
def __init__(self, configItem, icon: Union[str, QIcon, FluentIcon], title, content=None, texts=None, parent=None):
"""
Parameters
----------
configItem: OptionsConfigItem
configuration item operated by the card
iconPath: str
the path of icon
icon: str | QIcon | FluentIcon
the icon to be drawn
title: str
the title of card
......@@ -364,7 +367,7 @@ class ComboBoxSettingCard(SettingCard):
parent: QWidget
parent widget
"""
super().__init__(iconPath, title, content, parent)
super().__init__(icon, title, content, parent)
self.configItem = configItem
self.comboBox = ComboBox(self)
self.hBoxLayout.addWidget(self.comboBox, 0, Qt.AlignRight)
......
......@@ -4,8 +4,8 @@ from PyQt5.QtGui import QColor, QPainter
from PyQt5.QtWidgets import QAction, QPushButton, QWidget
from .menu import RoundMenu
from ...common.config import qconfig, isDarkTheme
from ...common.icon import FluentIconFactory as FIF
from ...common.config import isDarkTheme
from ...common.icon import FluentIcon as FIF
from ...common.style_sheet import setStyleSheet
......@@ -155,7 +155,7 @@ class ComboBox(QPushButton):
elif self.isPressed:
painter.setOpacity(0.7)
FIF.render(FIF.ARROW_DOWN, painter, QRectF(
FIF.ARROW_DOWN.render(painter, QRectF(
self.width()-22, self.height()/2-6, 10, 10))
......
# coding:utf-8
from typing import Union
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QIcon, QPainter
from PyQt5.QtWidgets import QWidget
from ...common.icon import FluentIcon, drawIcon
class IconWidget(QWidget):
""" Icon widget """
def __init__(self, icon: Union[str, QIcon, FluentIcon], parent=None):
super().__init__(parent=parent)
self.icon = icon
def paintEvent(self, e):
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing|QPainter.SmoothPixmapTransform)
drawIcon(self.icon, painter, self.rect())
......@@ -8,7 +8,7 @@ from PyQt5.QtWidgets import (QAction, QApplication, QMenu, QProxyStyle, QStyle,
QListWidgetItem)
from ...common.smooth_scroll import SmoothScroll
from ...common.icon import FluentIconFactory as FIF
from ...common.icon import FluentIcon as FIF
from ...common.icon import MenuIconEngine
from ...common.style_sheet import setStyleSheet
from ...common.config import isDarkTheme
......@@ -100,7 +100,7 @@ class SubMenuItemWidget(QWidget):
painter.setRenderHints(QPainter.Antialiasing)
# draw right arrow
FIF.render(FIF.CHEVRON_RIGHT, painter, QRectF(
FIF.CHEVRON_RIGHT.render(painter, QRectF(
self.width()-10, self.height()/2-9/2, 9, 9))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册