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

添加设置导航界面伸展宽度的方法

上级 e70c55f6
......@@ -81,6 +81,8 @@ The navigation panel has four display modes:
* `NavigationDisplayMode.MINIMAL`: Only a menu button on small window widths (you should add and manage the menu button to main window by yourself).
If you call `NavigationInterface.setExpandWidth()`, the large window width (1008px) will change accordingly.
### More examples
Here is an another style of navigation interface, and its corresponding example program is available at https://github.com/zhiyiYo/PyQt-Fluent-Widgets/tree/master/examples/navigation.
......
......@@ -155,8 +155,11 @@ class Window(FramelessWindow):
position=NavigationItemPostion.BOTTOM
)
#!IMPORTANT: don't forget set the default route key
self.navigationInterface.setDefaultRouteKey(self.musicInterface.objectName())
#!IMPORTANT: don't forget to set the default route key if you enable the return button
# self.navigationInterface.setDefaultRouteKey(self.musicInterface.objectName())
# set the maximum width
# self.navigationInterface.setExpandWidth(300)
self.stackWidget.currentChanged.connect(self.onCurrentInterfaceChanged)
self.stackWidget.setCurrentIndex(1)
......
......@@ -188,9 +188,12 @@ class Window(FramelessWindow):
position=NavigationItemPostion.BOTTOM
)
#!IMPORTANT: don't forget set the default route key
#!IMPORTANT: don't forget to set the default route key
self.navigationInterface.setDefaultRouteKey(self.musicInterface.objectName())
# set the maximum width
# self.navigationInterface.setExpandWidth(300)
self.stackWidget.currentChanged.connect(self.onCurrentInterfaceChanged)
self.stackWidget.setCurrentIndex(1)
......
......@@ -12,7 +12,7 @@ Examples are available at https://github.com/zhiyiYo/PyQt-Fluent-Widgets/tree/ma
:license: MIT, see LICENSE for more details.
"""
__version__ = "0.3.3"
__version__ = "0.3.4"
from .components import *
from .common import *
......
......@@ -111,6 +111,10 @@ class NavigationInterface(QWidget):
""" set the routing key to use when the navigation history is empty """
self.panel.setDefaultRouteKey(key)
def setExpandWidth(self, width: int):
""" set the maximum width """
self.panel.setExpandWidth(width)
def eventFilter(self, obj, e: QEvent):
if obj is not self.panel or e.type() != QEvent.Resize:
return super().eventFilter(obj, e)
......
......@@ -51,6 +51,7 @@ class NavigationPanel(QFrame):
self.history = NavigationHistory(self.items)
self.expandAni = QPropertyAnimation(self, b'geometry', self)
self.expandWidth = 322
self.isMinimalEnabled = isMinimalEnabled
if isMinimalEnabled:
......@@ -197,6 +198,14 @@ class NavigationPanel(QFrame):
""" set whether the menu button is visible """
self.returnButton.setVisible(isVisible)
def setExpandWidth(self, width: int):
""" set the maximum width """
if width <= 42:
return
self.expandWidth = width
NavigationWidget.EXPAND_WIDTH = width - 10
def expand(self):
""" expand navigation panel """
self._setWidgetCompacted(False)
......@@ -204,7 +213,8 @@ class NavigationPanel(QFrame):
# determine the display mode according to the width of window
# https://learn.microsoft.com/en-us/windows/apps/design/controls/navigationview#default
if self.window().width() > 1007 and not self.isMinimalEnabled:
expandWidth = 1007 + self.expandWidth - 322
if self.window().width() > expandWidth and not self.isMinimalEnabled:
self.displayMode = NavigationDisplayMode.EXPAND
else:
self.setProperty('menu', True)
......@@ -221,7 +231,7 @@ class NavigationPanel(QFrame):
self.expandAni.setStartValue(
QRect(self.pos(), QSize(48, self.height())))
self.expandAni.setEndValue(
QRect(self.pos(), QSize(322, self.height())))
QRect(self.pos(), QSize(self.expandWidth, self.height())))
self.expandAni.start()
def collapse(self):
......
......@@ -14,6 +14,7 @@ class NavigationWidget(QWidget):
""" Navigation widget """
clicked = pyqtSignal()
EXPAND_WIDTH = 312
def __init__(self, isSelectable: bool, parent=None):
super().__init__(parent)
......@@ -51,7 +52,7 @@ class NavigationWidget(QWidget):
if isCompacted:
self.setFixedSize(40, 36)
else:
self.setFixedSize(312, 36)
self.setFixedSize(self.EXPAND_WIDTH, 36)
self.update()
......@@ -150,7 +151,7 @@ class NavigationSeparator(NavigationWidget):
if isCompacted:
self.setFixedSize(48, 3)
else:
self.setFixedSize(322, 3)
self.setFixedSize(self.EXPAND_WIDTH + 10, 3)
self.update()
......
......@@ -6,7 +6,7 @@ with open('README.md', encoding='utf-8') as f:
setuptools.setup(
name="PyQt-Fluent-Widgets",
version="0.3.3",
version="0.3.4",
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.
先完成此消息的编辑!
想要评论请 注册