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

添加主界面 `FluentWindow`

上级 567c807d
......@@ -8,7 +8,6 @@ class StyleSheet(StyleSheetBase, Enum):
""" Style sheet """
LINK_CARD = "link_card"
MAIN_WINDOW = "main_window"
SAMPLE_CARD = "sample_card"
HOME_INTERFACE = "home_interface"
ICON_INTERFACE = "icon_interface"
......
# coding: utf-8
from PyQt5.QtCore import Qt, QRect
from PyQt5.QtGui import QPainter, QImage, QBrush, QColor, QFont
from qfluentwidgets import NavigationWidget, isDarkTheme
class AvatarWidget(NavigationWidget):
""" Avatar widget """
def __init__(self, image_path, parent=None):
super().__init__(isSelectable=False, parent=parent)
self.avatar = QImage(image_path).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')
\ No newline at end of file
......@@ -120,7 +120,6 @@
<file>qss/dark/home_interface.qss</file>
<file>qss/dark/icon_interface.qss</file>
<file>qss/dark/link_card.qss</file>
<file>qss/dark/main_window.qss</file>
<file>qss/dark/sample_card.qss</file>
<file>qss/dark/setting_interface.qss</file>
<file>qss/dark/view_interface.qss</file>
......@@ -130,7 +129,6 @@
<file>qss/light/home_interface.qss</file>
<file>qss/light/icon_interface.qss</file>
<file>qss/light/link_card.qss</file>
<file>qss/light/main_window.qss</file>
<file>qss/light/sample_card.qss</file>
<file>qss/light/setting_interface.qss</file>
<file>qss/light/view_interface.qss</file>
......
......@@ -22,6 +22,7 @@ class BasicInputInterface(GalleryInterface):
subtitle='qfluentwidgets.components.widgets',
parent=parent
)
self.setObjectName('basicInputInterface')
# simple push button
self.addExampleCard(
......
......@@ -16,6 +16,7 @@ class DateTimeInterface(GalleryInterface):
subtitle='qfluentwidgets.components.date_time',
parent=parent
)
self.setObjectName('dateTimeInterface')
# calendar picker
self.addExampleCard(
......
......@@ -16,6 +16,7 @@ class DialogInterface(GalleryInterface):
subtitle='qfluentwidgets.components.dialog_box',
parent=parent
)
self.setObjectName('dialogInterface')
button = PushButton(self.tr('Show dialog'))
button.clicked.connect(self.showDialog)
......
......@@ -17,6 +17,7 @@ class BannerWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.setFixedHeight(336)
self.vBoxLayout = QVBoxLayout(self)
self.galleryLabel = QLabel('Fluent Gallery', self)
self.banner = QPixmap(':/gallery/images/header1.png')
......@@ -103,6 +104,7 @@ class HomeInterface(ScrollArea):
def __initWidget(self):
self.view.setObjectName('view')
self.setObjectName('homeInterface')
StyleSheet.HOME_INTERFACE.apply(self)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
......
......@@ -229,6 +229,7 @@ class IconInterface(GalleryInterface):
subtitle="qfluentwidgets.common.icon",
parent=parent
)
self.setObjectName('iconInterface')
self.iconView = IconCardView(self)
self.vBoxLayout.addWidget(self.iconView)
......@@ -16,6 +16,7 @@ class LayoutInterface(GalleryInterface):
subtitle="qfluentwidgets.components.layout",
parent=parent
)
self.setObjectName('iconInterface')
self.addExampleCard(
self.tr('Flow layout without animation'),
......
# coding: utf-8
from typing import List
from PyQt5.QtCore import Qt, pyqtSignal, QEasingCurve, QUrl
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QIcon, QDesktopServices
from PyQt5.QtWidgets import QApplication, QHBoxLayout, QFrame, QWidget
from PyQt5.QtWidgets import QApplication
from qfluentwidgets import (NavigationInterface, NavigationItemPosition, MessageBox,
isDarkTheme, PopUpAniStackedWidget, qrouter)
from qfluentwidgets import NavigationAvatarWidget, NavigationItemPosition, MessageBox, FluentWindow
from qfluentwidgets import FluentIcon as FIF
from .title_bar import CustomTitleBar
from .gallery_interface import GalleryInterface
from .home_interface import HomeInterface
from .basic_input_interface import BasicInputInterface
......@@ -21,60 +18,19 @@ from .menu_interface import MenuInterface
from .navigation_view_interface import NavigationViewInterface
from .scroll_interface import ScrollInterface
from .status_info_interface import StatusInfoInterface
from .setting_interface import SettingInterface, cfg
from .setting_interface import SettingInterface
from .text_interface import TextInterface
from .view_interface import ViewInterface
from ..common.config import SUPPORT_URL
from ..components.avatar_widget import AvatarWidget
from ..components.frameless_window import FramelessWindow
from ..common.icon import Icon
from ..common.signal_bus import signalBus
from ..common.style_sheet import StyleSheet
from ..common import resource
class StackedWidget(QFrame):
""" Stacked widget """
currentWidgetChanged = pyqtSignal(QWidget)
def __init__(self, parent=None):
super().__init__(parent=parent)
self.hBoxLayout = QHBoxLayout(self)
self.view = PopUpAniStackedWidget(self)
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
self.hBoxLayout.addWidget(self.view)
self.view.currentChanged.connect(
lambda i: self.currentWidgetChanged.emit(self.view.widget(i)))
def addWidget(self, widget):
""" add widget to view """
self.view.addWidget(widget)
def setCurrentWidget(self, widget, popOut=True):
widget.verticalScrollBar().setValue(0)
if not popOut:
self.view.setCurrentWidget(widget, duration=300)
else:
self.view.setCurrentWidget(
widget, True, False, 200, QEasingCurve.InQuad)
def setCurrentIndex(self, index, popOut=False):
self.setCurrentWidget(self.view.widget(index), popOut)
class MainWindow(FramelessWindow):
class MainWindow(FluentWindow):
def __init__(self):
super().__init__()
self.setTitleBar(CustomTitleBar(self))
self.hBoxLayout = QHBoxLayout(self)
self.widgetLayout = QHBoxLayout()
self.stackWidget = StackedWidget(self)
self.navigationInterface = NavigationInterface(self, True, True)
# create sub interface
self.homeInterface = HomeInterface(self)
......@@ -101,108 +57,48 @@ class MainWindow(FramelessWindow):
self.initWindow()
def initLayout(self):
self.hBoxLayout.setSpacing(0)
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
self.hBoxLayout.addWidget(self.navigationInterface)
self.hBoxLayout.addLayout(self.widgetLayout)
self.hBoxLayout.setStretchFactor(self.widgetLayout, 1)
self.widgetLayout.addWidget(self.stackWidget)
self.widgetLayout.setContentsMargins(0, 48, 0, 0)
signalBus.switchToSampleCard.connect(self.switchToSample)
signalBus.supportSignal.connect(self.onSupport)
self.navigationInterface.displayModeChanged.connect(
self.titleBar.raise_)
self.titleBar.raise_()
def initNavigation(self):
# add navigation items
self.addSubInterface(
self.homeInterface, 'homeInterface', FIF.HOME, self.tr('Home'), NavigationItemPosition.TOP)
self.addSubInterface(
self.iconInterface, 'iconInterface', Icon.EMOJI_TAB_SYMBOLS, self.tr('Icons'), NavigationItemPosition.TOP)
self.addSubInterface(self.homeInterface, FIF.HOME, self.tr('Home'))
self.addSubInterface(self.iconInterface, Icon.EMOJI_TAB_SYMBOLS, self.tr('Icons'))
self.navigationInterface.addSeparator()
self.addSubInterface(
self.basicInputInterface, 'basicInputInterface', FIF.CHECKBOX, self.tr('Basic input'))
self.addSubInterface(
self.dateTimeInterface, 'dateTimeInterface', FIF.DATE_TIME, self.tr('Date & time'))
self.addSubInterface(
self.dialogInterface, 'dialogInterface', FIF.MESSAGE, self.tr('Dialogs'))
self.addSubInterface(
self.layoutInterface, 'layoutInterface', FIF.LAYOUT, self.tr('Layout'))
self.addSubInterface(
self.materialInterface, 'materialInterface', FIF.PALETTE, self.tr('Material'))
self.addSubInterface(
self.menuInterface, 'menuInterface', Icon.MENU, self.tr('Menus'))
self.addSubInterface(
self.navigationViewInterface, 'navigationViewInterface', FIF.MENU, self.tr('Navigation'))
self.addSubInterface(
self.scrollInterface, 'scrollInterface', FIF.SCROLL, self.tr('Scrolling'))
self.addSubInterface(
self.statusInfoInterface, 'statusInfoInterface', FIF.CHAT, self.tr('Status & info'))
self.addSubInterface(
self.textInterface, 'textInterface', Icon.TEXT, self.tr('Text'))
self.addSubInterface(
self.viewInterface, 'viewInterface', Icon.GRID, self.tr('View'))
pos = NavigationItemPosition.SCROLL
self.addSubInterface(self.basicInputInterface, FIF.CHECKBOX, self.tr('Basic input'), pos)
self.addSubInterface(self.dateTimeInterface, FIF.DATE_TIME, self.tr('Date & time'), pos)
self.addSubInterface(self.dialogInterface, FIF.MESSAGE, self.tr('Dialogs'), pos)
self.addSubInterface(self.layoutInterface, FIF.LAYOUT, self.tr('Layout'), pos)
self.addSubInterface(self.materialInterface, FIF.PALETTE, self.tr('Material'), pos)
self.addSubInterface(self.menuInterface, Icon.MENU, self.tr('Menus'), pos)
self.addSubInterface(self.navigationViewInterface, FIF.MENU, self.tr('Navigation'), pos)
self.addSubInterface(self.scrollInterface, FIF.SCROLL, self.tr('Scrolling'), pos)
self.addSubInterface(self.statusInfoInterface, FIF.CHAT, self.tr('Status & info'), pos)
self.addSubInterface(self.textInterface, Icon.TEXT, self.tr('Text'), pos)
self.addSubInterface(self.viewInterface, Icon.GRID, self.tr('View'), pos)
# add custom widget to bottom
self.navigationInterface.addWidget(
routeKey='avatar',
widget=AvatarWidget(':/gallery/images/shoko.png'),
widget=NavigationAvatarWidget('zhiyiYo', ':/gallery/images/shoko.png'),
onClick=self.onSupport,
position=NavigationItemPosition.BOTTOM
)
self.addSubInterface(
self.settingInterface, 'settingInterface', FIF.SETTING, self.tr('Settings'), NavigationItemPosition.BOTTOM)
#!IMPORTANT: don't forget to set the default route key if you enable the return button
qrouter.setDefaultRouteKey(self.stackWidget, self.homeInterface.objectName())
self.stackWidget.currentWidgetChanged.connect(self.onCurrentWidgetChanged)
self.navigationInterface.setCurrentItem(
self.homeInterface.objectName())
self.stackWidget.setCurrentIndex(0)
def addSubInterface(self, interface: QWidget, objectName: str, icon, text: str, position=NavigationItemPosition.SCROLL):
""" add sub interface """
interface.setObjectName(objectName)
self.stackWidget.addWidget(interface)
self.navigationInterface.addItem(
routeKey=objectName,
icon=icon,
text=text,
onClick=lambda t: self.switchTo(interface, t),
position=position,
tooltip=text
)
self.settingInterface, FIF.SETTING, self.tr('Settings'), NavigationItemPosition.BOTTOM)
def initWindow(self):
self.resize(960, 780)
self.setMinimumWidth(760)
self.setWindowIcon(QIcon(':/gallery/images/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)
StyleSheet.MAIN_WINDOW.apply(self)
def switchTo(self, widget, triggerByUser=True):
self.stackWidget.setCurrentWidget(widget, not triggerByUser)
def onCurrentWidgetChanged(self, widget: QWidget):
self.navigationInterface.setCurrentItem(widget.objectName())
qrouter.push(self.stackWidget, widget.objectName())
def resizeEvent(self, e):
self.titleBar.move(46, 0)
self.titleBar.resize(self.width()-46, self.titleBar.height())
def onSupport(self):
w = MessageBox(
'支持作者🥰',
......@@ -219,5 +115,5 @@ class MainWindow(FramelessWindow):
interfaces = self.findChildren(GalleryInterface)
for w in interfaces:
if w.objectName() == routeKey:
self.stackWidget.setCurrentWidget(w, False)
self.stackedWidget.setCurrentWidget(w, False)
w.scrollToCard(index)
......@@ -18,6 +18,7 @@ class MaterialInterface(GalleryInterface):
subtitle='qfluentwidgets.components.widgets',
parent=parent
)
self.setObjectName('materialInterface')
self.label = AcrylicLabel(
cfg.get(cfg.blurRadius), QColor(105, 114, 168, 102))
......
......@@ -18,6 +18,7 @@ class MenuInterface(GalleryInterface):
subtitle='qfluentwidgets.components.widgets',
parent=parent
)
self.setObjectName('menuInterface')
button = PushButton(self.tr('Show menu'))
button.clicked.connect(lambda: self.createMenu(
......
......@@ -18,6 +18,7 @@ class NavigationViewInterface(GalleryInterface):
subtitle="qfluentwidgets.components.navigation",
parent=parent
)
self.setObjectName('navigationViewInterface')
self.addExampleCard(
title=self.tr('A basic pivot'),
......
......@@ -18,6 +18,7 @@ class ScrollInterface(GalleryInterface):
subtitle="qfluentwidgets.components.widgets",
parent=parent
)
self.setObjectName('scrollInterface')
# scroll area
w = ScrollArea()
......
......@@ -148,6 +148,7 @@ class SettingInterface(ScrollArea):
self.setViewportMargins(0, 80, 0, 20)
self.setWidget(self.scrollWidget)
self.setWidgetResizable(True)
self.setObjectName('settingInterface')
# initialize style sheet
self.scrollWidget.setObjectName('scrollWidget')
......
......@@ -20,6 +20,7 @@ class StatusInfoInterface(GalleryInterface):
subtitle="qfluentwidgets.components.widgets",
parent=parent
)
self.setObjectName('statusInfoInterface')
# state tool tip
self.stateTooltip = None
......
......@@ -17,6 +17,7 @@ class TextInterface(GalleryInterface):
subtitle="qfluentwidgets.components.widgets",
parent=parent
)
self.setObjectName('textInterface')
# line edit
lineEdit = LineEdit(self)
......
# coding: utf-8
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QLabel, QHBoxLayout, QVBoxLayout
from qframelesswindow import TitleBar
class CustomTitleBar(TitleBar):
""" Title bar with icon and title """
def __init__(self, parent):
super().__init__(parent)
self.setFixedHeight(48)
self.hBoxLayout.removeWidget(self.minBtn)
self.hBoxLayout.removeWidget(self.maxBtn)
self.hBoxLayout.removeWidget(self.closeBtn)
# add window icon
self.iconLabel = QLabel(self)
self.iconLabel.setFixedSize(18, 18)
self.hBoxLayout.insertSpacing(0, 10)
self.hBoxLayout.insertWidget(1, self.iconLabel, 0, Qt.AlignLeft | Qt.AlignVCenter)
self.window().windowIconChanged.connect(self.setIcon)
# add title label
self.titleLabel = QLabel(self)
self.hBoxLayout.insertWidget(2, self.titleLabel, 0, Qt.AlignLeft | Qt.AlignVCenter)
self.titleLabel.setObjectName('titleLabel')
self.window().windowTitleChanged.connect(self.setTitle)
self.vBoxLayout = QVBoxLayout()
self.buttonLayout = QHBoxLayout()
self.buttonLayout.setSpacing(0)
self.buttonLayout.setContentsMargins(0, 0, 0, 0)
self.buttonLayout.setAlignment(Qt.AlignTop)
self.buttonLayout.addWidget(self.minBtn)
self.buttonLayout.addWidget(self.maxBtn)
self.buttonLayout.addWidget(self.closeBtn)
self.vBoxLayout.addLayout(self.buttonLayout)
self.vBoxLayout.addStretch(1)
self.hBoxLayout.addLayout(self.vBoxLayout, 0)
def setTitle(self, title):
self.titleLabel.setText(title)
self.titleLabel.adjustSize()
def setIcon(self, icon):
self.iconLabel.setPixmap(QIcon(icon).pixmap(18, 18))
......@@ -19,6 +19,7 @@ class ViewInterface(GalleryInterface):
subtitle="qfluentwidgets.components.widgets",
parent=parent
)
self.setObjectName('viewInterface')
# list view
self.addExampleCard(
......
......@@ -5,7 +5,7 @@ from PyQt5.QtGui import QIcon, QPainter, QImage, QBrush, QColor, QFont, QDesktop
from PyQt5.QtWidgets import QApplication, QFrame, QStackedWidget, QHBoxLayout, QLabel
from qfluentwidgets import (NavigationInterface, NavigationItemPosition, NavigationWidget, MessageBox,
isDarkTheme, setTheme, Theme, setThemeColor, qrouter)
isDarkTheme, setTheme, Theme, setThemeColor, qrouter, FluentWindow, NavigationAvatarWidget)
from qfluentwidgets import FluentIcon as FIF
from qframelesswindow import FramelessWindow, StandardTitleBar
......@@ -21,43 +21,6 @@ class Widget(QFrame):
self.setObjectName(text.replace(' ', '-'))
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')
class Window(FramelessWindow):
......@@ -127,7 +90,7 @@ class Window(FramelessWindow):
# add custom widget to bottom
self.navigationInterface.addWidget(
routeKey='avatar',
widget=AvatarWidget(),
widget=NavigationAvatarWidget('zhiyiYo', 'resource/shoko.png'),
onClick=self.showMessageBox,
position=NavigationItemPosition.BOTTOM,
)
......
......@@ -9,7 +9,7 @@ Widget {
Window {
background-color: rgb(39, 39, 39);
background-color: rgb(32, 32, 32);
}
CustomTitleBar {
......
# coding:utf-8
import sys
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QIcon, QDesktopServices
from PyQt5.QtWidgets import QApplication, QFrame, QHBoxLayout
from qfluentwidgets import (NavigationItemPosition, MessageBox, setTheme, Theme, FluentWindow,
NavigationAvatarWidget, qrouter, SubtitleLabel, setFont)
from qfluentwidgets import FluentIcon as FIF
class Widget(QFrame):
def __init__(self, text: str, parent=None):
super().__init__(parent=parent)
self.label = SubtitleLabel(text, self)
self.hBoxLayout = QHBoxLayout(self)
setFont(self.label, 24)
self.label.setAlignment(Qt.AlignCenter)
self.hBoxLayout.addWidget(self.label, 1, Qt.AlignCenter)
self.setObjectName(text.replace(' ', '-'))
class Window(FluentWindow):
def __init__(self):
super().__init__()
# create sub interface
self.homeInterface = Widget('Search Interface', self)
self.musicInterface = Widget('Music Interface', self)
self.videoInterface = Widget('Video Interface', self)
self.folderInterface = Widget('Folder Interface', self)
self.settingInterface = Widget('Setting Interface', self)
self.albumInterface = Widget('Album Interface', self)
self.albumInterface1 = Widget('Album Interface 1', self)
self.albumInterface2 = Widget('Album Interface 2', self)
self.albumInterface1_1 = Widget('Album Interface 1-1', self)
self.initNavigation()
self.initWindow()
def initNavigation(self):
self.addSubInterface(self.homeInterface, FIF.HOME, 'Home')
self.addSubInterface(self.musicInterface, FIF.MUSIC, 'Music library')
self.addSubInterface(self.videoInterface, FIF.VIDEO, 'Video library')
self.navigationInterface.addSeparator()
self.addSubInterface(self.albumInterface, FIF.ALBUM, 'Albums', NavigationItemPosition.SCROLL)
self.addSubInterface(self.albumInterface1, FIF.ALBUM, 'Album 1', parent=self.albumInterface)
self.addSubInterface(self.albumInterface1_1, FIF.ALBUM, 'Album 1.1', parent=self.albumInterface1)
self.addSubInterface(self.albumInterface2, FIF.ALBUM, 'Album 2', parent=self.albumInterface)
self.addSubInterface(self.folderInterface, FIF.FOLDER, 'Folder library', NavigationItemPosition.SCROLL)
# add custom widget to bottom
self.navigationInterface.addWidget(
routeKey='avatar',
widget=NavigationAvatarWidget('zhiyiYo', 'resource/shoko.png'),
onClick=self.showMessageBox,
position=NavigationItemPosition.BOTTOM,
)
self.addSubInterface(self.settingInterface, FIF.SETTING, 'Settings', NavigationItemPosition.BOTTOM)
def initWindow(self):
self.resize(900, 700)
self.setWindowIcon(QIcon(':/qfluentwidgets/images/logo.png'))
self.setWindowTitle('PyQt-Fluent-Widgets')
desktop = QApplication.desktop().availableGeometry()
w, h = desktop.width(), desktop.height()
self.move(w//2 - self.width()//2, h//2 - self.height()//2)
def showMessageBox(self):
w = MessageBox(
'支持作者🥰',
'个人开发不易,如果这个项目帮助到了您,可以考虑请作者喝一瓶快乐水🥤。您的支持就是作者开发和维护项目的动力🚀',
self
)
w.yesButton.setText('来啦老弟')
w.cancelButton.setText('下次一定')
if w.exec():
QDesktopServices.openUrl(QUrl("https://afdian.net/a/zhiyiYo"))
if __name__ == '__main__':
QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
setTheme(Theme.DARK)
app = QApplication(sys.argv)
w = Window()
w.show()
app.exec_()
# coding:utf-8
import sys
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QIcon, QDesktopServices
from PyQt5.QtWidgets import QApplication, QFrame, QHBoxLayout
from qfluentwidgets import (NavigationItemPosition, MessageBox, setTheme, Theme, MSFluentWindow,
NavigationAvatarWidget, qrouter, SubtitleLabel, setFont)
from qfluentwidgets import FluentIcon as FIF
class Widget(QFrame):
def __init__(self, text: str, parent=None):
super().__init__(parent=parent)
self.label = SubtitleLabel(text, self)
self.hBoxLayout = QHBoxLayout(self)
setFont(self.label, 24)
self.label.setAlignment(Qt.AlignCenter)
self.hBoxLayout.addWidget(self.label, 1, Qt.AlignCenter)
self.setObjectName(text.replace(' ', '-'))
class Window(MSFluentWindow):
def __init__(self):
super().__init__()
# create sub interface
self.homeInterface = Widget('Home Interface', self)
self.appInterface = Widget('Application Interface', self)
self.videoInterface = Widget('Video Interface', self)
self.libraryInterface = Widget('library Interface', self)
self.initNavigation()
self.initWindow()
def initNavigation(self):
self.addSubInterface(self.homeInterface, FIF.HOME, '主页', FIF.HOME_FILL)
self.addSubInterface(self.appInterface, FIF.APPLICATION, '应用')
self.addSubInterface(self.videoInterface, FIF.VIDEO, '视频')
self.addSubInterface(self.libraryInterface, FIF.BOOK_SHELF, '库', FIF.LIBRARY_FILL, NavigationItemPosition.BOTTOM)
self.navigationInterface.addItem(
routeKey='Help',
icon=FIF.HELP,
text='帮助',
onClick=self.showMessageBox,
selectable=False,
position=NavigationItemPosition.BOTTOM,
)
self.navigationInterface.setCurrentItem(self.homeInterface.objectName())
def initWindow(self):
self.resize(900, 700)
self.setWindowIcon(QIcon(':/qfluentwidgets/images/logo.png'))
self.setWindowTitle('PyQt-Fluent-Widgets')
desktop = QApplication.desktop().availableGeometry()
w, h = desktop.width(), desktop.height()
self.move(w//2 - self.width()//2, h//2 - self.height()//2)
def showMessageBox(self):
w = MessageBox(
'支持作者🥰',
'个人开发不易,如果这个项目帮助到了您,可以考虑请作者喝一瓶快乐水🥤。您的支持就是作者开发和维护项目的动力🚀',
self
)
w.yesButton.setText('来啦老弟')
w.cancelButton.setText('下次一定')
if w.exec():
QDesktopServices.openUrl(QUrl("https://afdian.net/a/zhiyiYo"))
if __name__ == '__main__':
QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
# setTheme(Theme.DARK)
app = QApplication(sys.argv)
w = Window()
w.show()
app.exec_()
# coding:utf-8
import sys
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QIcon, QDesktopServices
from PyQt5.QtWidgets import QApplication, QFrame, QHBoxLayout
from qfluentwidgets import (NavigationItemPosition, MessageBox, setTheme, Theme, SplitFluentWindow,
NavigationAvatarWidget, qrouter, SubtitleLabel, setFont)
from qfluentwidgets import FluentIcon as FIF
class Widget(QFrame):
def __init__(self, text: str, parent=None):
super().__init__(parent=parent)
self.label = SubtitleLabel(text, self)
self.hBoxLayout = QHBoxLayout(self)
setFont(self.label, 24)
self.label.setAlignment(Qt.AlignCenter)
self.hBoxLayout.addWidget(self.label, 1, Qt.AlignCenter)
self.setObjectName(text.replace(' ', '-'))
# !IMPORTANT: leave some space for title bar
self.hBoxLayout.setContentsMargins(0, 32, 0, 0)
class Window(SplitFluentWindow):
def __init__(self):
super().__init__()
# create sub interface
self.homeInterface = Widget('Home Interface', self)
self.musicInterface = Widget('Music Interface', self)
self.videoInterface = Widget('Video Interface', self)
self.folderInterface = Widget('Folder Interface', self)
self.settingInterface = Widget('Setting Interface', self)
self.albumInterface = Widget('Album Interface', self)
self.albumInterface1 = Widget('Album Interface 1', self)
self.albumInterface2 = Widget('Album Interface 2', self)
self.albumInterface1_1 = Widget('Album Interface 1-1', self)
self.initNavigation()
self.initWindow()
def initNavigation(self):
self.addSubInterface(self.homeInterface, FIF.HOME, 'Home')
self.addSubInterface(self.musicInterface, FIF.MUSIC, 'Music library')
self.addSubInterface(self.videoInterface, FIF.VIDEO, 'Video library')
self.navigationInterface.addSeparator()
self.addSubInterface(self.albumInterface, FIF.ALBUM, 'Albums', NavigationItemPosition.SCROLL)
self.addSubInterface(self.albumInterface1, FIF.ALBUM, 'Album 1', parent=self.albumInterface)
self.addSubInterface(self.albumInterface1_1, FIF.ALBUM, 'Album 1.1', parent=self.albumInterface1)
self.addSubInterface(self.albumInterface2, FIF.ALBUM, 'Album 2', parent=self.albumInterface)
self.addSubInterface(self.folderInterface, FIF.FOLDER, 'Folder library', NavigationItemPosition.SCROLL)
# add custom widget to bottom
self.navigationInterface.addWidget(
routeKey='avatar',
widget=NavigationAvatarWidget('zhiyiYo', 'resource/shoko.png'),
onClick=self.showMessageBox,
position=NavigationItemPosition.BOTTOM,
)
self.addSubInterface(self.settingInterface, FIF.SETTING, 'Settings', NavigationItemPosition.BOTTOM)
def initWindow(self):
self.resize(900, 700)
self.setWindowIcon(QIcon(':/qfluentwidgets/images/logo.png'))
self.setWindowTitle('PyQt-Fluent-Widgets')
desktop = QApplication.desktop().availableGeometry()
w, h = desktop.width(), desktop.height()
self.move(w//2 - self.width()//2, h//2 - self.height()//2)
def showMessageBox(self):
w = MessageBox(
'支持作者🥰',
'个人开发不易,如果这个项目帮助到了您,可以考虑请作者喝一瓶快乐水🥤。您的支持就是作者开发和维护项目的动力🚀',
self
)
w.yesButton.setText('来啦老弟')
w.cancelButton.setText('下次一定')
if w.exec():
QDesktopServices.openUrl(QUrl("https://afdian.net/a/zhiyiYo"))
if __name__ == '__main__':
QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
setTheme(Theme.DARK)
app = QApplication(sys.argv)
w = Window()
w.show()
app.exec_()
......@@ -12,8 +12,9 @@ Examples are available at https://github.com/zhiyiYo/PyQt-Fluent-Widgets/tree/ma
:license: GPLv3, see LICENSE for more details.
"""
__version__ = "0.9.7"
__version__ = "0.9.8"
from .components import *
from .common import *
from .window import *
from ._rc import resource
\ No newline at end of file
StackedWidget {
border: 1px solid rgb(29, 29, 29);
border-right: none;
border-bottom: none;
border-top-left-radius: 10px;
background-color: rgb(39, 39, 39);
}
MainWindow {
FluentWindowBase {
background-color: rgb(32, 32, 32);
}
CustomTitleBar {
FluentTitleBar, SplitTitleBar {
background-color: transparent;
}
CustomTitleBar>QLabel#titleLabel {
FluentTitleBar>QLabel#titleLabel,
SplitTitleBar>QLabel#titleLabel {
background: transparent;
font: 13px 'Segoe UI';
padding: 0 4px;
color: white;
}
MSFluentTitleBar>QLabel#titleLabel {
padding: 0 10px
}
SplitTitleBar>QLabel#titleLabel {
padding: 0 5px
}
MinimizeButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
......@@ -47,3 +47,19 @@ CloseButton {
qproperty-normalBackgroundColor: transparent;
}
StackedWidget {
border: 1px solid rgb(29, 29, 29);
border-right: none;
border-bottom: none;
border-top-left-radius: 10px;
background-color: rgb(39, 39, 39);
}
StackedWidget QLabel {
color: white;
}
SplitFluentWindow > StackedWidget {
border-top-left-radius: 0px;
border-top: none;
}
......@@ -18,6 +18,6 @@ QScrollArea,
background-color: transparent;
}
NavigationInterface {
/* NavigationInterface {
background-color: rgb(32, 32, 32);
}
\ No newline at end of file
} */
\ No newline at end of file
......@@ -6,17 +6,35 @@ StackedWidget {
background-color: rgb(249, 249, 249);
}
MainWindow {
SplitFluentWindow>StackedWidget {
border-top-left-radius: 0px;
border-top: none;
}
FluentWindowBase {
background-color: rgb(243, 243, 243);
}
CustomTitleBar > QLabel#titleLabel {
FluentTitleBar, SplitTitleBar {
background-color: transparent;
}
FluentTitleBar>QLabel#titleLabel,
SplitTitleBar>QLabel#titleLabel {
color: black;
background: transparent;
font: 13px 'Segoe UI';
padding: 0 4px
}
MSFluentTitleBar>QLabel#titleLabel {
padding: 0 10px
}
SplitTitleBar>QLabel#titleLabel {
padding: 0 5px
}
MinimizeButton {
qproperty-normalColor: black;
qproperty-normalBackgroundColor: transparent;
......
......@@ -17,6 +17,6 @@ QScrollArea, #scrollWidget {
background-color: transparent;
}
NavigationInterface {
/* NavigationInterface {
background-color: rgb(243, 243, 243);
}
\ No newline at end of file
} */
\ No newline at end of file
此差异已折叠。
......@@ -242,6 +242,7 @@
<file>qss/dark/time_picker.qss</file>
<file>qss/dark/pivot.qss</file>
<file>qss/dark/calendar_picker.qss</file>
<file>qss/dark/fluent_window.qss</file>
<file>qss/light/color_dialog.qss</file>
<file>qss/light/dialog.qss</file>
......@@ -268,6 +269,7 @@
<file>qss/light/time_picker.qss</file>
<file>qss/light/pivot.qss</file>
<file>qss/light/calendar_picker.qss</file>
<file>qss/light/fluent_window.qss</file>
<file>i18n/qfluentwidgets.zh_CN.qm</file>
<file>i18n/qfluentwidgets.zh_HK.qm</file>
......
......@@ -103,6 +103,7 @@ class FluentStyleSheet(StyleSheetBase, Enum):
TIME_PICKER = "time_picker"
SETTING_CARD = "setting_card"
COLOR_DIALOG = "color_dialog"
FLUENT_WINDOW = "fluent_window"
SWITCH_BUTTON = "switch_button"
MESSAGE_DIALOG = "message_dialog"
STATE_TOOL_TIP = "state_tool_tip"
......
from .navigation_widget import (NavigationWidget, NavigationPushButton, NavigationSeparator, NavigationToolButton,
NavigationTreeWidget, NavigationTreeWidgetBase)
NavigationTreeWidget, NavigationTreeWidgetBase, NavigationAvatarWidget)
from .navigation_panel import NavigationPanel, NavigationItemPosition, NavigationDisplayMode
from .navigation_interface import NavigationInterface
from .navigation_bar import NavigationBarPushButton, NavigationBar
......
......@@ -312,12 +312,3 @@ class NavigationBar(QWidget):
widget = self.sender() # type: NavigationWidget
if widget.isSelectable:
self.setCurrentItem(widget.property('routeKey'))
#def resizeEvent(self, e):
# if e.oldSize().height() == self.height():
# return
#
# th = self.topLayout.minimumSize().height()
# bh = self.bottomLayout.minimumSize().height()
# h = self.height() - th - bh - 20
# self.scrollArea.setFixedHeight(max(h, 58))
......@@ -42,8 +42,7 @@ class NavigationInterface(QWidget):
self.resize(48, self.height())
self.setMinimumWidth(48)
self.setAttribute(Qt.WA_StyledBackground)
FluentStyleSheet.NAVIGATION_INTERFACE.apply(self)
self.setAttribute(Qt.WA_TranslucentBackground)
def addItem(self, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None,
selectable=True, position=NavigationItemPosition.TOP, tooltip: str = None,
......
......@@ -3,7 +3,7 @@ from typing import Union, List
from PyQt5.QtCore import (Qt, pyqtSignal, QRect, QRectF, QPropertyAnimation, pyqtProperty, QMargins,
QEasingCurve, QPoint, QEvent)
from PyQt5.QtGui import QColor, QPainter, QPen, QIcon, QCursor, QFont
from PyQt5.QtGui import QColor, QPainter, QPen, QIcon, QCursor, QFont, QBrush, QPixmap, QImage
from PyQt5.QtWidgets import QWidget, QVBoxLayout
from ...common.config import isDarkTheme
......@@ -425,3 +425,52 @@ class NavigationTreeWidget(NavigationTreeWidgetBase):
if not clickArrow or self.isCompacted:
self.clicked.emit(triggerByUser)
class NavigationAvatarWidget(NavigationWidget):
""" Avatar widget """
def __init__(self, name: str, avatar: Union[str, QPixmap, QImage], parent=None):
super().__init__(isSelectable=False, parent=parent)
self.name = name
self.setAvatar(avatar)
setFont(self)
def setName(self, name: str):
self.name = name
self.update()
def setAvatar(self, avatar: Union[str, QPixmap, QImage]):
if isinstance(avatar, str):
avatar = QImage(avatar)
elif isinstance(avatar, QPixmap):
avatar = avatar.toImage()
self.avatar = avatar.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)
painter.setFont(self.font())
painter.drawText(QRect(44, 0, 255, 36), Qt.AlignVCenter, self.name)
from .fluent_window import FluentWindow, MSFluentWindow, SplitFluentWindow
\ No newline at end of file
# coding:utf-8
from typing import Union
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QPainter, QColor
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QLabel
from ..common.icon import FluentIconBase
from ..common.router import qrouter
from ..common.style_sheet import FluentStyleSheet, isDarkTheme
from ..components.widgets.frameless_window import FramelessWindow
from ..components.navigation import (NavigationInterface, NavigationBar, NavigationItemPosition,
NavigationBarPushButton, NavigationTreeWidget)
from .stacked_widget import StackedWidget
from qframelesswindow import TitleBar
class FluentWindowBase(FramelessWindow):
""" Fluent window base class """
def __init__(self, parent=None):
super().__init__(parent=parent)
self.hBoxLayout = QHBoxLayout(self)
self.stackedWidget = StackedWidget(self)
self.navigationInterface = None
# initialize layout
self.hBoxLayout.setSpacing(0)
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
FluentStyleSheet.FLUENT_WINDOW.apply(self.stackedWidget)
def addSubInterface(self, interface: QWidget, icon: Union[FluentIconBase, QIcon, str], text: str,
position=NavigationItemPosition.TOP):
""" add sub interface """
raise NotImplementedError
def switchTo(self, interface: QWidget):
self.stackedWidget.setCurrentWidget(interface, popOut=False)
def _onCurrentInterfaceChanged(self, index: int):
widget = self.stackedWidget.widget(index)
self.navigationInterface.setCurrentItem(widget.objectName())
qrouter.push(self.stackedWidget, widget.objectName())
def paintEvent(self, e):
painter = QPainter(self)
painter.setPen(Qt.NoPen)
if isDarkTheme():
painter.setBrush(QColor(32, 32, 32))
else:
painter.setBrush(QColor(243, 243, 243))
painter.drawRect(self.rect())
class FluentTitleBar(TitleBar):
""" Fluent title bar"""
def __init__(self, parent):
super().__init__(parent)
self.setFixedHeight(48)
self.hBoxLayout.removeWidget(self.minBtn)
self.hBoxLayout.removeWidget(self.maxBtn)
self.hBoxLayout.removeWidget(self.closeBtn)
# add window icon
self.iconLabel = QLabel(self)
self.iconLabel.setFixedSize(18, 18)
self.hBoxLayout.insertWidget(0, self.iconLabel, 0, Qt.AlignLeft | Qt.AlignVCenter)
self.window().windowIconChanged.connect(self.setIcon)
# add title label
self.titleLabel = QLabel(self)
self.hBoxLayout.insertWidget(1, self.titleLabel, 0, Qt.AlignLeft | Qt.AlignVCenter)
self.titleLabel.setObjectName('titleLabel')
self.window().windowTitleChanged.connect(self.setTitle)
self.vBoxLayout = QVBoxLayout()
self.buttonLayout = QHBoxLayout()
self.buttonLayout.setSpacing(0)
self.buttonLayout.setContentsMargins(0, 0, 0, 0)
self.buttonLayout.setAlignment(Qt.AlignTop)
self.buttonLayout.addWidget(self.minBtn)
self.buttonLayout.addWidget(self.maxBtn)
self.buttonLayout.addWidget(self.closeBtn)
self.vBoxLayout.addLayout(self.buttonLayout)
self.vBoxLayout.addStretch(1)
self.hBoxLayout.addLayout(self.vBoxLayout, 0)
FluentStyleSheet.FLUENT_WINDOW.apply(self)
def setTitle(self, title):
self.titleLabel.setText(title)
self.titleLabel.adjustSize()
def setIcon(self, icon):
self.iconLabel.setPixmap(QIcon(icon).pixmap(18, 18))
class FluentWindow(FluentWindowBase):
""" Fluent window """
def __init__(self, parent=None):
super().__init__(parent)
self.setTitleBar(FluentTitleBar(self))
self.navigationInterface = NavigationInterface(self, showReturnButton=True)
self.widgetLayout = QHBoxLayout()
# initialize layout
self.hBoxLayout.addWidget(self.navigationInterface)
self.hBoxLayout.addLayout(self.widgetLayout)
self.hBoxLayout.setStretchFactor(self.widgetLayout, 1)
self.widgetLayout.addWidget(self.stackedWidget)
self.widgetLayout.setContentsMargins(0, 48, 0, 0)
self.navigationInterface.displayModeChanged.connect(self.titleBar.raise_)
self.titleBar.raise_()
def addSubInterface(self, interface: QWidget, icon: Union[FluentIconBase, QIcon, str], text: str,
position=NavigationItemPosition.TOP, parent=None) -> NavigationTreeWidget:
""" add sub interface, the object name of `interface` should be set already
before calling this method
Parameters
----------
interface: QWidget
the subinterface to be added
icon: FluentIconBase | QIcon | str
the icon of navigation item
text: str
the text of navigation item
position: NavigationItemPosition
the position of navigation item
parent: QWidget
the parent of navigation item
"""
if not interface.objectName():
raise ValueError("The object name of `interface` can't be empty string.")
if parent and not parent.objectName():
raise ValueError("The object name of `parent` can't be empty string.")
self.stackedWidget.addWidget(interface)
# add navigation item
routeKey = interface.objectName()
item = self.navigationInterface.addItem(
routeKey=routeKey,
icon=icon,
text=text,
onClick=lambda: self.switchTo(interface),
position=position,
tooltip=text,
parentRouteKey=parent.objectName() if parent else None
)
# initialize selected item
if self.stackedWidget.count() == 1:
self.stackedWidget.currentChanged.connect(self._onCurrentInterfaceChanged)
self.navigationInterface.setCurrentItem(routeKey)
qrouter.setDefaultRouteKey(self.stackedWidget, routeKey)
return item
def resizeEvent(self, e):
self.titleBar.move(46, 0)
self.titleBar.resize(self.width()-46, self.titleBar.height())
class MSFluentTitleBar(FluentTitleBar):
def __init__(self, parent):
super().__init__(parent)
self.hBoxLayout.insertSpacing(0, 20)
self.hBoxLayout.insertSpacing(2, 2)
class MSFluentWindow(FluentWindowBase):
""" Fluent window in Microsoft Store style """
def __init__(self, parent=None):
super().__init__(parent)
self.setTitleBar(MSFluentTitleBar(self))
self.navigationInterface = NavigationBar(self)
# initialize layout
self.hBoxLayout.setContentsMargins(0, 48, 0, 0)
self.hBoxLayout.addWidget(self.navigationInterface)
self.hBoxLayout.addWidget(self.stackedWidget, 1)
self.titleBar.raise_()
self.titleBar.setAttribute(Qt.WA_StyledBackground)
def addSubInterface(self, interface: QWidget, icon: Union[FluentIconBase, QIcon, str], text: str,
selectedIcon=None, position=NavigationItemPosition.TOP) -> NavigationBarPushButton:
""" add sub interface, the object name of `interface` should be set already
before calling this method
Parameters
----------
interface: QWidget
the subinterface to be added
icon: FluentIconBase | QIcon | str
the icon of navigation item
text: str
the text of navigation item
selectedIcon: str | QIcon | FluentIconBase
the icon of navigation item in selected state
position: NavigationItemPosition
the position of navigation item
"""
if not interface.objectName():
raise ValueError("The object name of `interface` can't be empty string.")
self.stackedWidget.addWidget(interface)
# add navigation item
routeKey = interface.objectName()
item = self.navigationInterface.addItem(
routeKey=routeKey,
icon=icon,
text=text,
onClick=lambda: self.switchTo(interface),
selectedIcon=selectedIcon,
position=position
)
if self.stackedWidget.count() == 1:
self.stackedWidget.currentChanged.connect(self._onCurrentInterfaceChanged)
self.navigationInterface.setCurrentItem(routeKey)
qrouter.setDefaultRouteKey(self.stackedWidget, routeKey)
return item
class SplitTitleBar(TitleBar):
def __init__(self, parent):
super().__init__(parent)
# add window icon
self.iconLabel = QLabel(self)
self.iconLabel.setFixedSize(18, 18)
self.hBoxLayout.insertSpacing(0, 12)
self.hBoxLayout.insertWidget(1, self.iconLabel, 0, Qt.AlignLeft | Qt.AlignBottom)
self.window().windowIconChanged.connect(self.setIcon)
# add title label
self.titleLabel = QLabel(self)
self.hBoxLayout.insertWidget(2, self.titleLabel, 0, Qt.AlignLeft | Qt.AlignBottom)
self.titleLabel.setObjectName('titleLabel')
self.window().windowTitleChanged.connect(self.setTitle)
FluentStyleSheet.FLUENT_WINDOW.apply(self)
def setTitle(self, title):
self.titleLabel.setText(title)
self.titleLabel.adjustSize()
def setIcon(self, icon):
self.iconLabel.setPixmap(QIcon(icon).pixmap(18, 18))
class SplitFluentWindow(FluentWindow):
""" Fluent window with split style """
def __init__(self, parent=None):
super().__init__(parent)
self.setTitleBar(SplitTitleBar(self))
self.widgetLayout.setContentsMargins(0, 0, 0, 0)
self.titleBar.raise_()
self.navigationInterface.displayModeChanged.connect(self.titleBar.raise_)
# coding:utf-8
from PyQt5.QtCore import Qt, pyqtSignal, QEasingCurve
from PyQt5.QtWidgets import QFrame, QHBoxLayout, QAbstractScrollArea
from ..components.widgets.stacked_widget import PopUpAniStackedWidget
class StackedWidget(QFrame):
""" Stacked widget """
currentChanged = pyqtSignal(int)
def __init__(self, parent=None):
super().__init__(parent=parent)
self.hBoxLayout = QHBoxLayout(self)
self.view = PopUpAniStackedWidget(self)
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
self.hBoxLayout.addWidget(self.view)
self.view.currentChanged.connect(self.currentChanged)
self.setAttribute(Qt.WA_StyledBackground)
def addWidget(self, widget):
""" add widget to view """
self.view.addWidget(widget)
def widget(self, index: int):
return self.view.widget(index)
def setCurrentWidget(self, widget, popOut=True):
if isinstance(widget, QAbstractScrollArea):
widget.verticalScrollBar().setValue(0)
if not popOut:
self.view.setCurrentWidget(widget, duration=300)
else:
self.view.setCurrentWidget(
widget, True, False, 200, QEasingCurve.InQuad)
def setCurrentIndex(self, index, popOut=True):
self.setCurrentWidget(self.view.widget(index), popOut)
def currentIndex(self):
return self.view.currentIndex()
def indexOf(self, widget):
return self.view.indexOf(widget)
def count(self):
return self.view.count()
\ No newline at end of file
......@@ -6,7 +6,7 @@ with open('README.md', encoding='utf-8') as f:
setuptools.setup(
name="PyQt-Fluent-Widgets",
version="0.9.7",
version="0.9.8",
keywords="pyqt fluent widgets",
author="zhiyiYo",
author_email="shokokawaii@outlook.com",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册