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

添加树状视图

上级 f4653567
...@@ -9,6 +9,7 @@ class Icon(FluentIconBase, Enum): ...@@ -9,6 +9,7 @@ class Icon(FluentIconBase, Enum):
HOME = "Home" HOME = "Home"
CHAT = "Chat" CHAT = "Chat"
CODE = "Code" CODE = "Code"
GRID = "Grid"
MENU = "Menu" MENU = "Menu"
TEXT = "Text" TEXT = "Text"
ALBUM = "Album" ALBUM = "Album"
......
...@@ -12,6 +12,7 @@ class StyleSheet(StyleSheetBase, Enum): ...@@ -12,6 +12,7 @@ class StyleSheet(StyleSheetBase, Enum):
SAMPLE_CARD = "sample_card" SAMPLE_CARD = "sample_card"
HOME_INTERFACE = "home_interface" HOME_INTERFACE = "home_interface"
ICON_INTERFACE = "icon_interface" ICON_INTERFACE = "icon_interface"
VIEW_INTERFACE = "view_interface"
SETTING_INTERFACE = "setting_interface" SETTING_INTERFACE = "setting_interface"
GALLERY_INTERFACE = "gallery_interface" GALLERY_INTERFACE = "gallery_interface"
......
...@@ -14,4 +14,5 @@ class Translator(QObject): ...@@ -14,4 +14,5 @@ class Translator(QObject):
self.scroll = self.tr('Scrolling') self.scroll = self.tr('Scrolling')
self.layout = self.tr('Layout') self.layout = self.tr('Layout')
self.text = self.tr('Text') self.text = self.tr('Text')
self.icons = self.tr('Icons') self.icons = self.tr('Icons')
\ No newline at end of file self.view = self.tr('View')
\ No newline at end of file
...@@ -270,65 +270,70 @@ ...@@ -270,65 +270,70 @@
<context> <context>
<name>MainWindow</name> <name>MainWindow</name>
<message> <message>
<location filename="../../view/main_window.py" line="137"/> <location filename="../../view/main_window.py" line="141"/>
<source>Home</source> <source>Home</source>
<translation>主頁</translation> <translation>主頁</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="151"/> <location filename="../../view/main_window.py" line="155"/>
<source>Basic input</source> <source>Basic input</source>
<translation>基本輸入</translation> <translation>基本輸入</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="158"/> <location filename="../../view/main_window.py" line="162"/>
<source>Dialogs</source> <source>Dialogs</source>
<translation>對話框</translation> <translation>對話框</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="165"/> <location filename="../../view/main_window.py" line="169"/>
<source>Layout</source> <source>Layout</source>
<translation>佈局</translation> <translation>佈局</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="179"/> <location filename="../../view/main_window.py" line="183"/>
<source>Menus</source> <source>Menus</source>
<translation>菜單</translation> <translation>菜單</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="172"/> <location filename="../../view/main_window.py" line="176"/>
<source>Material</source> <source>Material</source>
<translation>材料</translation> <translation>材料</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="186"/> <location filename="../../view/main_window.py" line="190"/>
<source>Scrolling</source> <source>Scrolling</source>
<translation>滾動</translation> <translation>滾動</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="193"/> <location filename="../../view/main_window.py" line="197"/>
<source>Status &amp; info</source> <source>Status &amp; info</source>
<translation>狀態和信息</translation> <translation>狀態和信息</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="255"/> <location filename="../../view/main_window.py" line="266"/>
<source>This is a help message</source> <source>This is a help message</source>
<translation>一條友善的提示</translation> <translation>一條友善的提示</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="255"/> <location filename="../../view/main_window.py" line="266"/>
<source>You clicked a customized navigation widget. You can add more custom widgets by calling `NavigationInterface.addWidget()` 😉</source> <source>You clicked a customized navigation widget. You can add more custom widgets by calling `NavigationInterface.addWidget()` 😉</source>
<translation>你點擊了一個自定義的導航項你可以通過 `NavigationInterface.addWidget()` 添加更多的自定義導航項</translation> <translation>你點擊了一個自定義的導航項你可以通過 `NavigationInterface.addWidget()` 添加更多的自定義導航項</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="200"/> <location filename="../../view/main_window.py" line="204"/>
<source>Text</source> <source>Text</source>
<translation>文本</translation> <translation>文本</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="143"/> <location filename="../../view/main_window.py" line="147"/>
<source>Icons</source> <source>Icons</source>
<translation>圖標</translation> <translation>圖標</translation>
</message> </message>
<message>
<location filename="../../view/main_window.py" line="211"/>
<source>View</source>
<translation>視圖</translation>
</message>
</context> </context>
<context> <context>
<name>MaterialInterface</name> <name>MaterialInterface</name>
...@@ -913,5 +918,56 @@ ...@@ -913,5 +918,56 @@
<source>Icons</source> <source>Icons</source>
<translation>圖標</translation> <translation>圖標</translation>
</message> </message>
<message>
<location filename="../../common/translator.py" line="18"/>
<source>View</source>
<translation>視圖</translation>
</message>
</context>
<context>
<name>TreeFrame</name>
<message>
<location filename="../../view/view_interface.py" line="59"/>
<source>JoJo 1 - Phantom Blood</source>
<translation>JoJo 1 - 幻影之血</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="60"/>
<source>Jonathan Joestar</source>
<translation>喬納森·喬斯達</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="60"/>
<source>Dio Brando</source>
<translation>迪奧·佈蘭度</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="60"/>
<source>Will A. Zeppeli</source>
<translation>威廉·A·齊貝林</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="67"/>
<source>JoJo 3 - Stardust Crusaders</source>
<translation>JoJo3 - 星塵鬥士</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="68"/>
<source>Jotaro Kujo</source>
<translation></translation>
</message>
</context>
<context>
<name>ViewInterface</name>
<message>
<location filename="../../view/view_interface.py" line="23"/>
<source>A simple TreeView</source>
<translation>簡單的樹狀組件</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="30"/>
<source>A TreeView with Multi-selection enabled</source>
<translation>啟用複選框的樹狀組件</translation>
</message>
</context> </context>
</TS> </TS>
...@@ -270,65 +270,70 @@ ...@@ -270,65 +270,70 @@
<context> <context>
<name>MainWindow</name> <name>MainWindow</name>
<message> <message>
<location filename="../../view/main_window.py" line="137"/> <location filename="../../view/main_window.py" line="141"/>
<source>Home</source> <source>Home</source>
<translation>主页</translation> <translation>主页</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="151"/> <location filename="../../view/main_window.py" line="155"/>
<source>Basic input</source> <source>Basic input</source>
<translation>基本输入</translation> <translation>基本输入</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="158"/> <location filename="../../view/main_window.py" line="162"/>
<source>Dialogs</source> <source>Dialogs</source>
<translation>对话框</translation> <translation>对话框</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="165"/> <location filename="../../view/main_window.py" line="169"/>
<source>Layout</source> <source>Layout</source>
<translation>布局</translation> <translation>布局</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="179"/> <location filename="../../view/main_window.py" line="183"/>
<source>Menus</source> <source>Menus</source>
<translation>菜单</translation> <translation>菜单</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="172"/> <location filename="../../view/main_window.py" line="176"/>
<source>Material</source> <source>Material</source>
<translation>材料</translation> <translation>材料</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="186"/> <location filename="../../view/main_window.py" line="190"/>
<source>Scrolling</source> <source>Scrolling</source>
<translation>滚动</translation> <translation>滚动</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="193"/> <location filename="../../view/main_window.py" line="197"/>
<source>Status &amp; info</source> <source>Status &amp; info</source>
<translation>状态和信息</translation> <translation>状态和信息</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="255"/> <location filename="../../view/main_window.py" line="266"/>
<source>This is a help message</source> <source>This is a help message</source>
<translation>一条友善的提示</translation> <translation>一条友善的提示</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="255"/> <location filename="../../view/main_window.py" line="266"/>
<source>You clicked a customized navigation widget. You can add more custom widgets by calling `NavigationInterface.addWidget()` 😉</source> <source>You clicked a customized navigation widget. You can add more custom widgets by calling `NavigationInterface.addWidget()` 😉</source>
<translation>你点击了一个自定义的导航项你可以通过 `NavigationInterface.addWidget()` 添加更多的自定义导航项</translation> <translation>你点击了一个自定义的导航项你可以通过 `NavigationInterface.addWidget()` 添加更多的自定义导航项</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="200"/> <location filename="../../view/main_window.py" line="204"/>
<source>Text</source> <source>Text</source>
<translation>文本</translation> <translation>文本</translation>
</message> </message>
<message> <message>
<location filename="../../view/main_window.py" line="143"/> <location filename="../../view/main_window.py" line="147"/>
<source>Icons</source> <source>Icons</source>
<translation>图标</translation> <translation>图标</translation>
</message> </message>
<message>
<location filename="../../view/main_window.py" line="211"/>
<source>View</source>
<translation>视图</translation>
</message>
</context> </context>
<context> <context>
<name>MaterialInterface</name> <name>MaterialInterface</name>
...@@ -913,5 +918,56 @@ ...@@ -913,5 +918,56 @@
<source>Icons</source> <source>Icons</source>
<translation>图标</translation> <translation>图标</translation>
</message> </message>
<message>
<location filename="../../common/translator.py" line="18"/>
<source>View</source>
<translation>视图</translation>
</message>
</context>
<context>
<name>TreeFrame</name>
<message>
<location filename="../../view/view_interface.py" line="59"/>
<source>JoJo 1 - Phantom Blood</source>
<translation>JoJo 1 - 幻影之血</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="60"/>
<source>Jonathan Joestar</source>
<translation>乔纳森·乔斯达</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="60"/>
<source>Dio Brando</source>
<translation>迪奥·布兰度</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="60"/>
<source>Will A. Zeppeli</source>
<translation>威廉·A·齐贝林</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="67"/>
<source>JoJo 3 - Stardust Crusaders</source>
<translation>JoJo3 - 星尘斗士</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="68"/>
<source>Jotaro Kujo</source>
<translation></translation>
</message>
</context>
<context>
<name>ViewInterface</name>
<message>
<location filename="../../view/view_interface.py" line="23"/>
<source>A simple TreeView</source>
<translation>简单的树状组件</translation>
</message>
<message>
<location filename="../../view/view_interface.py" line="30"/>
<source>A TreeView with Multi-selection enabled</source>
<translation>启用复选框的树状组件</translation>
</message>
</context> </context>
</TS> </TS>
...@@ -40,6 +40,17 @@ ...@@ -40,6 +40,17 @@
<translation>取消</translation> <translation>取消</translation>
</message> </message>
</context> </context>
<context>
<name>MessageBox</name>
<message>
<source>OK</source>
<translation>確認</translation>
</message>
<message>
<source>Cancel</source>
<translation>取消</translation>
</message>
</context>
<context> <context>
<name>Dialog</name> <name>Dialog</name>
<message> <message>
......
...@@ -40,6 +40,17 @@ ...@@ -40,6 +40,17 @@
<translation>取消</translation> <translation>取消</translation>
</message> </message>
</context> </context>
<context>
<name>MessageBox</name>
<message>
<source>OK</source>
<translation>确认</translation>
</message>
<message>
<source>Cancel</source>
<translation>取消</translation>
</message>
</context>
<context> <context>
<name>Dialog</name> <name>Dialog</name>
<message> <message>
......
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048" enable-background="new 0 0 2048 2048"
xml:space="preserve"><path fill="#000000" d="M1828.57 0 q44.57 0 84.57 17.14 q40 17.14 70.29 47.43 q30.28 30.28 47.43 70.29 q17.14 40 17.14 84.57 l0 1609.14 q0 44.57 -17.14 84.57 q-17.14 40 -47.43 70.29 q-30.29 30.28 -70.29 47.43 q-40 17.14 -84.57 17.14 l-1609.14 0 q-44.57 0 -84.57 -17.14 q-40 -17.14 -70.29 -47.43 q-30.29 -30.29 -47.43 -70.29 q-17.14 -40 -17.14 -84.57 l0 -1609.14 q0 -44.57 17.14 -84.57 q17.14 -40 47.43 -70.29 q30.28 -30.29 70.29 -47.43 q40 -17.14 84.57 -17.14 l1609.14 0 ZM219.43 146.29 q-29.72 0 -51.43 21.71 q-21.71 21.71 -21.71 51.43 l0 365.71 l438.85 0 l0 -438.85 l-365.71 0 ZM731.43 146.29 l0 438.85 l585.14 0 l0 -438.85 l-585.14 0 ZM1901.71 219.43 q0 -29.72 -21.71 -51.43 q-21.71 -21.71 -51.43 -21.71 l-365.71 0 l0 438.85 l438.85 0 l0 -365.71 ZM585.14 731.43 l-438.85 0 l0 585.14 l438.85 0 l0 -585.14 ZM731.43 731.43 l0 585.14 l585.14 0 l0 -585.14 l-585.14 0 ZM1901.71 731.43 l-438.85 0 l0 585.14 l438.85 0 l0 -585.14 ZM146.29 1828.57 q0 29.72 21.71 51.43 q21.71 21.71 51.43 21.71 l365.71 0 l0 -438.85 l-438.85 0 l0 365.71 ZM1316.57 1901.71 l0 -438.85 l-585.14 0 l0 438.85 l585.14 0 ZM1828.57 1901.71 q29.72 0 51.43 -21.71 q21.71 -21.71 21.71 -51.43 l0 -365.71 l-438.85 0 l0 438.85 l365.71 0 Z"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048" enable-background="new 0 0 2048 2048"
xml:space="preserve"><path fill="#ffffff" d="M1828.57 0 q44.57 0 84.57 17.14 q40 17.14 70.29 47.43 q30.28 30.28 47.43 70.29 q17.14 40 17.14 84.57 l0 1609.14 q0 44.57 -17.14 84.57 q-17.14 40 -47.43 70.29 q-30.29 30.28 -70.29 47.43 q-40 17.14 -84.57 17.14 l-1609.14 0 q-44.57 0 -84.57 -17.14 q-40 -17.14 -70.29 -47.43 q-30.29 -30.29 -47.43 -70.29 q-17.14 -40 -17.14 -84.57 l0 -1609.14 q0 -44.57 17.14 -84.57 q17.14 -40 47.43 -70.29 q30.28 -30.29 70.29 -47.43 q40 -17.14 84.57 -17.14 l1609.14 0 ZM219.43 146.29 q-29.72 0 -51.43 21.71 q-21.71 21.71 -21.71 51.43 l0 365.71 l438.85 0 l0 -438.85 l-365.71 0 ZM731.43 146.29 l0 438.85 l585.14 0 l0 -438.85 l-585.14 0 ZM1901.71 219.43 q0 -29.72 -21.71 -51.43 q-21.71 -21.71 -51.43 -21.71 l-365.71 0 l0 438.85 l438.85 0 l0 -365.71 ZM585.14 731.43 l-438.85 0 l0 585.14 l438.85 0 l0 -585.14 ZM731.43 731.43 l0 585.14 l585.14 0 l0 -585.14 l-585.14 0 ZM1901.71 731.43 l-438.85 0 l0 585.14 l438.85 0 l0 -585.14 ZM146.29 1828.57 q0 29.72 21.71 51.43 q21.71 21.71 51.43 21.71 l365.71 0 l0 -438.85 l-438.85 0 l0 365.71 ZM1316.57 1901.71 l0 -438.85 l-585.14 0 l0 438.85 l585.14 0 ZM1828.57 1901.71 q29.72 0 51.43 -21.71 q21.71 -21.71 21.71 -51.43 l0 -365.71 l-438.85 0 l0 438.85 l365.71 0 Z"/></svg>
\ No newline at end of file
#frame {
border: 1px solid rgba(255, 255, 255, 13);
border-radius: 5px;
background-color: transparent;
}
\ No newline at end of file
#frame {
border: 1px solid rgba(0, 0, 0, 15);
border-radius: 5px;
background-color: transparent;
}
\ No newline at end of file
...@@ -22,6 +22,7 @@ from .scroll_interface import ScrollInterface ...@@ -22,6 +22,7 @@ from .scroll_interface import ScrollInterface
from .status_info_interface import StatusInfoInterface from .status_info_interface import StatusInfoInterface
from .setting_interface import SettingInterface, cfg from .setting_interface import SettingInterface, cfg
from .text_interface import TextInterface from .text_interface import TextInterface
from .view_interface import ViewInterface
from ..components.avatar_widget import AvatarWidget from ..components.avatar_widget import AvatarWidget
from ..common.icon import Icon from ..common.icon import Icon
from ..common.signal_bus import signalBus from ..common.signal_bus import signalBus
...@@ -83,6 +84,7 @@ class MainWindow(FramelessWindow): ...@@ -83,6 +84,7 @@ class MainWindow(FramelessWindow):
self.statusInfoInterface = StatusInfoInterface(self) self.statusInfoInterface = StatusInfoInterface(self)
self.settingInterface = SettingInterface(self) self.settingInterface = SettingInterface(self)
self.textInterface = TextInterface(self) self.textInterface = TextInterface(self)
self.viewInterface = ViewInterface(self)
self.stackWidget.addWidget(self.homeInterface) self.stackWidget.addWidget(self.homeInterface)
self.stackWidget.addWidget(self.iconInterface) self.stackWidget.addWidget(self.iconInterface)
...@@ -95,6 +97,7 @@ class MainWindow(FramelessWindow): ...@@ -95,6 +97,7 @@ class MainWindow(FramelessWindow):
self.stackWidget.addWidget(self.statusInfoInterface) self.stackWidget.addWidget(self.statusInfoInterface)
self.stackWidget.addWidget(self.settingInterface) self.stackWidget.addWidget(self.settingInterface)
self.stackWidget.addWidget(self.textInterface) self.stackWidget.addWidget(self.textInterface)
self.stackWidget.addWidget(self.viewInterface)
# initialize layout # initialize layout
self.initLayout() self.initLayout()
...@@ -132,6 +135,7 @@ class MainWindow(FramelessWindow): ...@@ -132,6 +135,7 @@ class MainWindow(FramelessWindow):
self.scrollInterface.setObjectName('scrollInterface') self.scrollInterface.setObjectName('scrollInterface')
self.settingInterface.setObjectName('settingsInterface') self.settingInterface.setObjectName('settingsInterface')
self.textInterface.setObjectName('textInterface') self.textInterface.setObjectName('textInterface')
self.viewInterface.setObjectName('viewInterface')
# add navigation items # add navigation items
self.navigationInterface.addItem( self.navigationInterface.addItem(
...@@ -204,6 +208,13 @@ class MainWindow(FramelessWindow): ...@@ -204,6 +208,13 @@ class MainWindow(FramelessWindow):
onClick=lambda t: self.switchTo(self.textInterface, t), onClick=lambda t: self.switchTo(self.textInterface, t),
position=NavigationItemPostion.SCROLL position=NavigationItemPostion.SCROLL
) )
self.navigationInterface.addItem(
routeKey=self.viewInterface.objectName(),
icon=Icon.GRID,
text=self.tr('View'),
onClick=lambda t: self.switchTo(self.viewInterface, t),
position=NavigationItemPostion.SCROLL
)
# add custom widget to bottom # add custom widget to bottom
self.navigationInterface.addWidget( self.navigationInterface.addWidget(
......
# coding:utf-8
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QFrame, QTreeWidgetItem, QHBoxLayout, QTreeWidgetItemIterator
from qfluentwidgets import TreeWidget
from .gallery_interface import GalleryInterface
from ..common.translator import Translator
from ..common.style_sheet import StyleSheet
class ViewInterface(GalleryInterface):
""" View interface """
def __init__(self, parent=None):
t = Translator()
super().__init__(
title=t.view,
subtitle="qfluentwidgets.components.widgets",
parent=parent
)
frame = TreeFrame(self)
self.addExampleCard(
title=self.tr('A simple TreeView'),
widget=frame,
sourcePath='https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/tree_view/demo.py'
)
frame = TreeFrame(self, True)
self.addExampleCard(
title=self.tr('A TreeView with Multi-selection enabled'),
widget=frame,
sourcePath='https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/tree_view/demo.py'
)
class Frame(QFrame):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.hBoxLayout = QHBoxLayout(self)
self.hBoxLayout.setContentsMargins(0, 8, 0, 0)
self.setObjectName('frame')
StyleSheet.VIEW_INTERFACE.apply(self)
def addWidget(self, widget):
self.hBoxLayout.addWidget(widget)
class TreeFrame(Frame):
def __init__(self, parent=None, enableCheck=False):
super().__init__(parent)
self.tree = TreeWidget(self)
self.addWidget(self.tree)
item1 = QTreeWidgetItem([self.tr('JoJo 1 - Phantom Blood')])
item1.addChildren([
QTreeWidgetItem([self.tr('Jonathan Joestar')]),
QTreeWidgetItem([self.tr('Dio Brando')]),
QTreeWidgetItem([self.tr('Will A. Zeppeli')]),
])
self.tree.addTopLevelItem(item1)
item2 = QTreeWidgetItem([self.tr('JoJo 3 - Stardust Crusaders')])
item21 = QTreeWidgetItem([self.tr('Jotaro Kujo')])
item21.addChildren([
QTreeWidgetItem(['空条承太郎']),
QTreeWidgetItem(['空条蕉太狼']),
QTreeWidgetItem(['阿强']),
QTreeWidgetItem(['卖鱼强']),
QTreeWidgetItem(['那个无敌的男人']),
])
item2.addChild(item21)
self.tree.addTopLevelItem(item2)
self.tree.expandAll()
self.tree.setHeaderHidden(True)
self.setFixedSize(300, 380)
if enableCheck:
it = QTreeWidgetItemIterator(self.tree)
while(it.value()):
it.value().setCheckState(0, Qt.Unchecked)
it += 1
...@@ -11,6 +11,7 @@ SOURCES += app/view/main_window.py \ ...@@ -11,6 +11,7 @@ SOURCES += app/view/main_window.py \
app/view/layout_interface.py \ app/view/layout_interface.py \
app/view/text_interface.py \ app/view/text_interface.py \
app/view/icon_interface.py \ app/view/icon_interface.py \
app/view/view_interface.py \
TRANSLATIONS += app/resource/i18n/gallery_zh.ts \ TRANSLATIONS += app/resource/i18n/gallery_zh.ts \
app/resource/i18n/gallery_hk.ts app/resource/i18n/gallery_hk.ts
# coding:utf-8
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QTreeWidgetItem, QFileSystemModel, QHBoxLayout
from qfluentwidgets import TreeWidget, setTheme, Theme, TreeView
class Demo(QWidget):
""" 树形控件演示 """
def __init__(self):
super().__init__()
self.hBoxLayout = QHBoxLayout(self)
self.setStyleSheet("Demo{background:rgb(255,255,255)}")
# setTheme(Theme.DARK)
self.view = TreeView(self)
model = QFileSystemModel()
model.setRootPath('.')
self.view.setModel(model)
self.hBoxLayout.addWidget(self.view)
self.hBoxLayout.setContentsMargins(30, 30, 30, 30)
self.resize(700, 600)
if __name__ == '__main__':
# enable dpi scale
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
app = QApplication(sys.argv)
w = Demo()
w.show()
sys.exit(app.exec_())
...@@ -12,7 +12,7 @@ Examples are available at https://github.com/zhiyiYo/PyQt-Fluent-Widgets/tree/ma ...@@ -12,7 +12,7 @@ Examples are available at https://github.com/zhiyiYo/PyQt-Fluent-Widgets/tree/ma
:license: GPLv3, see LICENSE for more details. :license: GPLv3, see LICENSE for more details.
""" """
__version__ = "0.6.8" __version__ = "0.6.9"
from .components import * from .components import *
from .common import * from .common import *
......
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 6000 6000" enable-background="new 0 0 6000 6000"
xml:space="preserve"><path fill="#383838" transform="translate(1900, 2000)" d="M448.28 1919.06 q0 -52.47 37.48 -89.95 l805.11 -805.11 l-805.11 -805.11 q-37.48 -37.48 -37.48 -89.95 q0 -52.48 36.74 -90.71 q36.74 -38.23 90.71 -38.23 q52.47 0 89.95 37.48 l896.57 896.56 q37.48 37.49 37.48 89.96 q0 52.47 -37.48 89.96 l-896.57 896.56 q-37.48 37.48 -89.95 37.48 q-53.97 0 -90.71 -38.23 q-36.74 -38.23 -36.74 -90.71 Z"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 6000 6000" enable-background="new 0 0 6000 6000"
xml:space="preserve"><path fill="#ffffff" transform="translate(1900, 2000)" d="M448.28 1919.06 q0 -52.47 37.48 -89.95 l805.11 -805.11 l-805.11 -805.11 q-37.48 -37.48 -37.48 -89.95 q0 -52.48 36.74 -90.71 q36.74 -38.23 90.71 -38.23 q52.47 0 89.95 37.48 l896.57 896.56 q37.48 37.49 37.48 89.96 q0 52.47 -37.48 89.96 l-896.57 896.56 q-37.48 37.48 -89.95 37.48 q-53.97 0 -90.71 -38.23 q-36.74 -38.23 -36.74 -90.71 Z"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 6000 6000" enable-background="new 0 0 6000 6000"
xml:space="preserve"><path fill="#383838" transform="translate(1800, 2500)" d="M0 128.94 q0 -26.99 10.49 -50.23 q10.49 -23.24 27.73 -40.48 q17.24 -17.24 40.48 -27.73 q23.24 -10.49 50.23 -10.49 q28.48 0 49.47 9.74 q20.99 9.74 40.48 29.23 l805.11 805.11 l805.11 -805.11 q38.98 -38.98 89.95 -38.98 q26.99 0 50.23 10.49 q23.24 10.49 40.48 27.73 q17.24 17.24 27.74 40.48 q10.49 23.24 10.49 50.23 q0 52.47 -37.48 89.95 l-896.56 896.57 q-37.49 37.48 -89.96 37.48 q-52.47 0 -89.96 -37.48 l-896.56 -896.57 q-37.48 -37.48 -37.48 -89.95 Z"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 6000 6000" enable-background="new 0 0 6000 6000"
xml:space="preserve"><path fill="#ffffff" transform="translate(1800, 2500)" d="M0 128.94 q0 -26.99 10.49 -50.23 q10.49 -23.24 27.73 -40.48 q17.24 -17.24 40.48 -27.73 q23.24 -10.49 50.23 -10.49 q28.48 0 49.47 9.74 q20.99 9.74 40.48 29.23 l805.11 805.11 l805.11 -805.11 q38.98 -38.98 89.95 -38.98 q26.99 0 50.23 10.49 q23.24 10.49 40.48 27.73 q17.24 17.24 27.74 40.48 q10.49 23.24 10.49 50.23 q0 52.47 -37.48 89.95 l-896.56 896.57 q-37.49 37.48 -89.96 37.48 q-52.47 0 -89.96 -37.48 l-896.56 -896.57 q-37.48 -37.48 -37.48 -89.95 Z"/></svg>
\ No newline at end of file
QTreeView {
background-color: transparent;
border: none;
border-radius: 5px;
outline: 0;
padding-right: 5px;
font: 13px 'Segoe UI', 'Microsoft YaHei';
}
QTreeView::item {
padding: 4px;
margin-top: 3px;
margin-bottom: 3px;
padding-left: 20px;
border-radius: 5px;
color: white;
}
QTreeView::branch:has-children:!has-siblings:closed,
QTreeView::branch:closed:has-children:has-siblings {
image: url(:/qfluentwidgets/images/tree_view/TreeViewClose_white.svg);
}
QTreeView::branch:open:has-children:!has-siblings,
QTreeView::branch:open:has-children:has-siblings {
image: url(:/qfluentwidgets/images/tree_view/TreeViewOpen_white.svg);
}
QTreeView:disabled {
color: rgba(255, 255, 255, 110);
}
QTreeView::indicator {
width: 18px;
height: 18px;
border-radius: 5px;
border: 1px solid rgb(159, 159, 159);
background-color: rgb(42, 42, 42);
}
QTreeView::indicator:hover {
border: 1px solid rgb(161, 161, 161);
background-color: rgb(56, 56, 56);
}
QTreeView::indicator:pressed {
border: 1px solid rgb(86, 86, 86);
background-color: rgb(62, 62, 62);
}
QTreeView::indicator:checked,
QTreeView::indicator:indeterminate {
background-color: --ThemeColorPrimary;
border: 1px solid --ThemeColorPrimary;
}
QTreeView::indicator:checked {
image: url(:/qfluentwidgets/images/check_box/Accept_black.svg);
}
QTreeView::indicator:indeterminate {
image: url(:/qfluentwidgets/images/check_box/PartialAccept_black.svg);
}
QTreeView::indicator:checked:hover,
QTreeView::indicator:indeterminate:hover {
border: 1px solid --ThemeColorDark1;
background-color: --ThemeColorDark1;
}
QTreeView::indicator:checked:pressed,
QTreeView::indicator:indeterminate:pressed {
border: 1px solid --ThemeColorDark2;
background-color: --ThemeColorDark2;
}
QTreeView::indicator:disabled {
border: 1px solid rgb(82, 82, 82);
background-color: rgb(45, 45, 45);
}
QTreeView::indicator:checked:disabled,
QTreeView::indicator:indeterminate:disabled {
border: 1px solid rgb(82, 82, 82);
background-color: rgb(82, 82, 82);
}
QScrollBar {
background: transparent;
width: 4px;
margin-top: 12px;
margin-bottom: 0;
padding-right: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
QTreeView {
background-color: transparent;
border: none;
border-radius: 5px;
outline: 0;
padding-right: 5px;
font: 13px 'Segoe UI', 'Microsoft YaHei';
}
QTreeView::item {
padding: 4px;
margin-top: 2px;
margin-bottom: 2px;
padding-left: 20px;
border-radius: 5px;
color: black;
}
QTreeView::branch:has-children:!has-siblings:closed,
QTreeView::branch:closed:has-children:has-siblings {
image: url(:/qfluentwidgets/images/tree_view/TreeViewClose_black.svg);
}
QTreeView::branch:open:has-children:!has-siblings,
QTreeView::branch:open:has-children:has-siblings {
image: url(:/qfluentwidgets/images/tree_view/TreeViewOpen_black.svg);
}
QTreeView:disabled {
color: rgba(0, 0, 0, 110);
}
QTreeView::indicator {
width: 18px;
height: 18px;
border-radius: 5px;
border: 1px solid rgb(135, 135, 135);
background-color: rgb(241, 241, 241);
}
QTreeView::indicator:hover {
border: 1px solid rgb(132, 132, 132);
background-color: rgb(232, 232, 232);
}
QTreeView::indicator:pressed {
border: 1px solid rgb(184, 184, 184);
background-color: rgb(224, 224, 224);
}
QTreeView::indicator:checked,
QTreeView::indicator:indeterminate {
border: 1px solid --ThemeColorPrimary;
background-color: --ThemeColorPrimary;
}
QTreeView::indicator:checked {
image: url(:/qfluentwidgets/images/check_box/Accept_white.svg);
}
QTreeView::indicator:indeterminate {
image: url(:/qfluentwidgets/images/check_box/PartialAccept_white.svg);
}
QTreeView::indicator:checked:hover,
QTreeView::indicator:indeterminate:hover {
border: 1px solid --ThemeColorLight1;
background-color: --ThemeColorLight1;
}
QTreeView::indicator:checked:pressed,
QTreeView::indicator:indeterminate:pressed {
border: 1px solid --ThemeColorLight3;
background-color: --ThemeColorLight3;
}
QTreeView::indicator:disabled {
border: 1px solid #bbbbbb;
background-color: rgb(224, 224, 224);
}
QTreeView::indicator:checked:disabled,
QTreeView::indicator:indeterminate:disabled {
border: 1px solid rgb(199, 199, 199);
background-color: rgb(199, 199, 199);
}
QScrollBar {
background: transparent;
width: 4px;
margin-top: 12px;
margin-bottom: 0;
padding-right: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
此差异已折叠。
...@@ -180,6 +180,10 @@ ...@@ -180,6 +180,10 @@
<file>images/spin_box/Up_black.svg</file> <file>images/spin_box/Up_black.svg</file>
<file>images/spin_box/Down_white.svg</file> <file>images/spin_box/Down_white.svg</file>
<file>images/spin_box/Down_black.svg</file> <file>images/spin_box/Down_black.svg</file>
<file>images/tree_view/TreeViewClose_black.svg</file>
<file>images/tree_view/TreeViewOpen_black.svg</file>
<file>images/tree_view/TreeViewClose_white.svg</file>
<file>images/tree_view/TreeViewOpen_white.svg</file>
<file>qss/dark/color_dialog.qss</file> <file>qss/dark/color_dialog.qss</file>
<file>qss/dark/dialog.qss</file> <file>qss/dark/dialog.qss</file>
...@@ -200,6 +204,7 @@ ...@@ -200,6 +204,7 @@
<file>qss/dark/check_box.qss</file> <file>qss/dark/check_box.qss</file>
<file>qss/dark/info_bar.qss</file> <file>qss/dark/info_bar.qss</file>
<file>qss/dark/spin_box.qss</file> <file>qss/dark/spin_box.qss</file>
<file>qss/dark/tree_view.qss</file>
<file>qss/light/color_dialog.qss</file> <file>qss/light/color_dialog.qss</file>
<file>qss/light/dialog.qss</file> <file>qss/light/dialog.qss</file>
...@@ -220,5 +225,6 @@ ...@@ -220,5 +225,6 @@
<file>qss/light/check_box.qss</file> <file>qss/light/check_box.qss</file>
<file>qss/light/info_bar.qss</file> <file>qss/light/info_bar.qss</file>
<file>qss/light/spin_box.qss</file> <file>qss/light/spin_box.qss</file>
<file>qss/light/tree_view.qss</file>
</qresource> </qresource>
</RCC> </RCC>
\ No newline at end of file
...@@ -96,6 +96,7 @@ class FluentStyleSheet(StyleSheetBase, Enum): ...@@ -96,6 +96,7 @@ class FluentStyleSheet(StyleSheetBase, Enum):
CHECK_BOX = "check_box" CHECK_BOX = "check_box"
COMBO_BOX = "combo_box" COMBO_BOX = "combo_box"
LINE_EDIT = "line_edit" LINE_EDIT = "line_edit"
TREE_VIEW = "tree_view"
SETTING_CARD = "setting_card" SETTING_CARD = "setting_card"
COLOR_DIALOG = "color_dialog" COLOR_DIALOG = "color_dialog"
SWITCH_BUTTON = "switch_button" SWITCH_BUTTON = "switch_button"
......
...@@ -12,4 +12,5 @@ from .spin_box import SpinBox, DoubleSpinBox, DateEdit, DateTimeEdit, TimeEdit ...@@ -12,4 +12,5 @@ from .spin_box import SpinBox, DoubleSpinBox, DateEdit, DateTimeEdit, TimeEdit
from .stacked_widget import PopUpAniStackedWidget, OpacityAniStackedWidget from .stacked_widget import PopUpAniStackedWidget, OpacityAniStackedWidget
from .state_tool_tip import StateToolTip from .state_tool_tip import StateToolTip
from .switch_button import SwitchButton, IndicatorPosition from .switch_button import SwitchButton, IndicatorPosition
from .tool_tip import ToolTip, ToolTipFilter from .tool_tip import ToolTip, ToolTipFilter
\ No newline at end of file from .tree_view import TreeWidget, TreeView
\ No newline at end of file
# coding:utf-8
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QPainter, QColor
from PyQt5.QtWidgets import QWidget, QTreeWidget, QStyledItemDelegate, QStyle, QTreeView
from ...common.style_sheet import FluentStyleSheet, themeColor, isDarkTheme
from ...common.smooth_scroll import SmoothScroll
class TreeItemDelegate(QStyledItemDelegate):
""" Tree item delegate """
def paint(self, painter, option, index):
painter.setRenderHints(
QPainter.Antialiasing | QPainter.TextAntialiasing)
super().paint(painter, option, index)
if not (option.state & (QStyle.State_Selected | QStyle.State_MouseOver)):
return
painter.save()
painter.setPen(Qt.NoPen)
# draw background
h = option.rect.height() - 4
c = 255 if isDarkTheme() else 0
painter.setBrush(QColor(c, c, c, 9))
painter.drawRoundedRect(
4, option.rect.y() + 2, self.parent().width() - 12, h, 4, 4)
# draw indicator
if option.state & QStyle.State_Selected:
painter.setBrush(themeColor())
painter.drawRoundedRect(4, 9+option.rect.y(), 3, h - 13, 1.5, 1.5)
painter.restore()
class TreeWidget(QTreeWidget):
""" Tree widget """
def __init__(self, parent=None):
super().__init__(parent=parent)
self.verticalSmoothScroll = SmoothScroll(self, Qt.Vertical)
self.horizonSmoothScroll = SmoothScroll(self, Qt.Horizontal)
self.setItemDelegate(TreeItemDelegate(self))
self.setIconSize(QSize(16, 16))
FluentStyleSheet.TREE_VIEW.apply(self)
def drawBranches(self, painter, rect, index):
rect.moveLeft(15)
return super().drawBranches(painter, rect, index)
def wheelEvent(self, e):
if e.modifiers() == Qt.NoModifier:
self.verticalSmoothScroll.wheelEvent(e)
else:
self.horizonSmoothScroll.wheelEvent(e)
class TreeView(QTreeView):
""" Tree view """
def __init__(self, parent=None):
super().__init__(parent=parent)
self.verticalSmoothScroll = SmoothScroll(self, Qt.Vertical)
self.horizonSmoothScroll = SmoothScroll(self, Qt.Horizontal)
self.setItemDelegate(TreeItemDelegate(self))
self.setIconSize(QSize(16, 16))
FluentStyleSheet.TREE_VIEW.apply(self)
FluentStyleSheet.TREE_VIEW.apply(self.verticalScrollBar())
def drawBranches(self, painter, rect, index):
rect.moveLeft(15)
return super().drawBranches(painter, rect, index)
def wheelEvent(self, e):
if e.modifiers() == Qt.NoModifier:
self.verticalSmoothScroll.wheelEvent(e)
else:
self.horizonSmoothScroll.wheelEvent(e)
...@@ -6,7 +6,7 @@ with open('README.md', encoding='utf-8') as f: ...@@ -6,7 +6,7 @@ with open('README.md', encoding='utf-8') as f:
setuptools.setup( setuptools.setup(
name="PyQt-Fluent-Widgets", name="PyQt-Fluent-Widgets",
version="0.6.8", version="0.6.9",
keywords="pyqt fluent widgets", keywords="pyqt fluent widgets",
author="zhiyiYo", author="zhiyiYo",
author_email="shokokawaii@outlook.com", author_email="shokokawaii@outlook.com",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册