You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libmangers/app/view/navigation_view_interface.py

73 lines
2.7 KiB

# coding:utf-8
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QWidget, QStackedWidget, QVBoxLayout, QLabel
from qfluentwidgets import Pivot, qrouter
from .gallery_interface import GalleryInterface
from ..common.style_sheet import StyleSheet
from ..common.translator import Translator
class NavigationViewInterface(GalleryInterface):
""" Navigation view interface """
def __init__(self, parent=None):
t = Translator()
super().__init__(
title=t.navigation,
subtitle="qfluentwidgets.components.navigation",
parent=parent
)
self.addExampleCard(
title=self.tr('A basic pivot'),
widget=PivotInterface(self),
sourcePath='https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/pivot/demo.py'
)
class PivotInterface(QWidget):
""" Pivot interface """
def __init__(self, parent=None):
super().__init__(parent=parent)
self.setFixedSize(300, 200)
self.pivot = Pivot(self)
self.stackedWidget = QStackedWidget(self)
self.vBoxLayout = QVBoxLayout(self)
self.songInterface = QLabel('Song Interface', self)
self.albumInterface = QLabel('Album Interface', self)
self.artistInterface = QLabel('Artist Interface', self)
# add items to pivot
self.addSubInterface(self.songInterface, 'songInterface', self.tr('Song'))
self.addSubInterface(self.albumInterface, 'albumInterface', self.tr('Album'))
self.addSubInterface(self.artistInterface, 'artistInterface', self.tr('Artist'))
self.vBoxLayout.addWidget(self.pivot, 0)
self.vBoxLayout.addWidget(self.stackedWidget)
self.vBoxLayout.setContentsMargins(0, 0, 0, 0)
StyleSheet.NAVIGATION_VIEW_INTERFACE.apply(self)
self.stackedWidget.currentChanged.connect(self.onCurrentIndexChanged)
self.stackedWidget.setCurrentWidget(self.songInterface)
self.pivot.setCurrentItem(self.songInterface.objectName())
qrouter.setDefaultRouteKey(self.stackedWidget, self.songInterface.objectName())
def addSubInterface(self, widget: QLabel, objectName, text):
widget.setObjectName(objectName)
widget.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.stackedWidget.addWidget(widget)
self.pivot.addItem(
routeKey=objectName,
text=text,
onClick=lambda: self.stackedWidget.setCurrentWidget(widget)
)
def onCurrentIndexChanged(self, index):
widget = self.stackedWidget.widget(index)
self.pivot.setCurrentItem(widget.objectName())
qrouter.push(self.stackedWidget, widget.objectName())