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

fixes #203, #221

上级 948dbde4
...@@ -9,7 +9,7 @@ assignees: '' ...@@ -9,7 +9,7 @@ assignees: ''
<!-- 作者还是一名学生党,有更加重要的事情等着自己完成。一个复杂的组件往往要花一到两天来完成,不仅费时费力且无任何经济收入,所以只会抽出一些周末时间来维护这个项目,响应 issue 的速度可能很慢。新组件将按照爱发电上的目标达成情况进行添加,请不要提关于新组件需求的 issue。考虑到代码风格和日后维护,不接受新组件的 PR。如果真的很想要这个组件,可以在爱发电上支持作者的开发。 <!-- 作者还是一名学生党,有更加重要的事情等着自己完成。一个复杂的组件往往要花一到两天来完成,不仅费时费力且无任何经济收入,所以只会抽出一些周末时间来维护这个项目,响应 issue 的速度可能很慢。新组件将按照爱发电上的目标达成情况进行添加,请不要提关于新组件需求的 issue。考虑到代码风格和日后维护,不接受新组件的 PR。如果真的很想要这个组件,可以在爱发电上支持作者的开发。
提 Issue 前请先搜索历史 Issue,可能有相似的,如果没有,需要补充完整模板要求的环境信息和最小复现代码,这很重要,不符合规范的 Issue 会被直接关闭哦。同时请注意礼貌用词,语句之间夹杂的阴阳怪气的省略号或者流汗黄豆绝对达咩 --> 提 Issue 前请先搜索历史 Issue,可能有相似的,如果没有,需要补充完整模板要求的环境信息和最小复现代码,并确保自己安装的包是最新版本的,这很重要,不符合规范的 Issue 会被直接关闭哦。同时请注意礼貌用词,语句之间夹杂的阴阳怪气的省略号或者流汗黄豆绝对达咩 -->
**Describe the bug** **Describe the bug**
A clear and concise description of what the bug is. A clear and concise description of what the bug is.
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -717,20 +717,28 @@ ...@@ -717,20 +717,28 @@
<translation>添加到</translation> <translation>添加到</translation>
</message> </message>
</context> </context>
<context>
<name>NavigationViewInterface</name>
<message>
<location filename="../../view/navigation_view_interface.py" line="22"/>
<source>A basic pivot</source>
<translation>顶部导航栏</translation>
</message>
</context>
<context> <context>
<name>PivotInterface</name> <name>PivotInterface</name>
<message> <message>
<location filename="../../view/navigation_view_interface.py" line="44"/> <location filename="../../view/navigation_view_interface.py" line="45"/>
<source>Song</source> <source>Song</source>
<translation>歌曲</translation> <translation>歌曲</translation>
</message> </message>
<message> <message>
<location filename="../../view/navigation_view_interface.py" line="45"/> <location filename="../../view/navigation_view_interface.py" line="46"/>
<source>Album</source> <source>Album</source>
<translation>专辑</translation> <translation>专辑</translation>
</message> </message>
<message> <message>
<location filename="../../view/navigation_view_interface.py" line="46"/> <location filename="../../view/navigation_view_interface.py" line="47"/>
<source>Artist</source> <source>Artist</source>
<translation>歌手</translation> <translation>歌手</translation>
</message> </message>
......
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
<message> <message>
<location filename="../../view/basic_input_interface.py" line="149"/> <location filename="../../view/basic_input_interface.py" line="149"/>
<source>Soft and Wet</source> <source>Soft and Wet</source>
<translation>軟又</translation> <translation>軟又</translation>
</message> </message>
<message> <message>
<location filename="../../view/basic_input_interface.py" line="241"/> <location filename="../../view/basic_input_interface.py" line="241"/>
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
<message> <message>
<location filename="../../view/basic_input_interface.py" line="107"/> <location filename="../../view/basic_input_interface.py" line="107"/>
<source>Send</source> <source>Send</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../../view/basic_input_interface.py" line="108"/> <location filename="../../view/basic_input_interface.py" line="108"/>
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
<message> <message>
<location filename="../../view/date_time_interface.py" line="41"/> <location filename="../../view/date_time_interface.py" line="41"/>
<source>A TimePicker using a 24-hour clock</source> <source>A TimePicker using a 24-hour clock</source>
<translation>24 小時的時間選擇器</translation> <translation>24 小時的時間選擇器</translation>
</message> </message>
<message> <message>
<location filename="../../view/date_time_interface.py" line="48"/> <location filename="../../view/date_time_interface.py" line="48"/>
...@@ -354,7 +354,7 @@ ...@@ -354,7 +354,7 @@
<message> <message>
<location filename="../../view/layout_interface.py" line="38"/> <location filename="../../view/layout_interface.py" line="38"/>
<source>Killer Queen</source> <source>Killer Queen</source>
<translation>殺手皇💀</translation> <translation>殺手皇💀</translation>
</message> </message>
<message> <message>
<location filename="../../view/layout_interface.py" line="39"/> <location filename="../../view/layout_interface.py" line="39"/>
...@@ -382,7 +382,7 @@ ...@@ -382,7 +382,7 @@
<message> <message>
<location filename="../../view/icon_interface.py" line="21"/> <location filename="../../view/icon_interface.py" line="21"/>
<source>Search icons</source> <source>Search icons</source>
<translation>索圖標</translation> <translation>索圖標</translation>
</message> </message>
</context> </context>
<context> <context>
...@@ -485,7 +485,7 @@ ...@@ -485,7 +485,7 @@
<message> <message>
<location filename="../../view/view_interface.py" line="85"/> <location filename="../../view/view_interface.py" line="85"/>
<source>Scary Monster</source> <source>Scary Monster</source>
<translation>駭人</translation> <translation>駭人</translation>
</message> </message>
<message> <message>
<location filename="../../view/view_interface.py" line="85"/> <location filename="../../view/view_interface.py" line="85"/>
...@@ -525,7 +525,7 @@ ...@@ -525,7 +525,7 @@
<message> <message>
<location filename="../../view/view_interface.py" line="89"/> <location filename="../../view/view_interface.py" line="89"/>
<source>SOFT &amp; WET</source> <source>SOFT &amp; WET</source>
<translation>軟又</translation> <translation>軟又</translation>
</message> </message>
<message> <message>
<location filename="../../view/view_interface.py" line="89"/> <location filename="../../view/view_interface.py" line="89"/>
...@@ -535,7 +535,7 @@ ...@@ -535,7 +535,7 @@
<message> <message>
<location filename="../../view/view_interface.py" line="90"/> <location filename="../../view/view_interface.py" line="90"/>
<source>Wonder of U</source> <source>Wonder of U</source>
<translation>於你</translation> <translation>於你</translation>
</message> </message>
<message> <message>
<location filename="../../view/view_interface.py" line="90"/> <location filename="../../view/view_interface.py" line="90"/>
...@@ -565,7 +565,7 @@ ...@@ -565,7 +565,7 @@
<message> <message>
<location filename="../../view/view_interface.py" line="79"/> <location filename="../../view/view_interface.py" line="79"/>
<source>Killer Queen</source> <source>Killer Queen</source>
<translation>殺手皇💀</translation> <translation>殺手皇💀</translation>
</message> </message>
</context> </context>
<context> <context>
...@@ -717,20 +717,28 @@ ...@@ -717,20 +717,28 @@
<translation>添加到</translation> <translation>添加到</translation>
</message> </message>
</context> </context>
<context>
<name>NavigationViewInterface</name>
<message>
<location filename="../../view/navigation_view_interface.py" line="22"/>
<source>A basic pivot</source>
<translation>頂部導航欄</translation>
</message>
</context>
<context> <context>
<name>PivotInterface</name> <name>PivotInterface</name>
<message> <message>
<location filename="../../view/navigation_view_interface.py" line="44"/> <location filename="../../view/navigation_view_interface.py" line="45"/>
<source>Song</source> <source>Song</source>
<translation>歌曲</translation> <translation>歌曲</translation>
</message> </message>
<message> <message>
<location filename="../../view/navigation_view_interface.py" line="45"/> <location filename="../../view/navigation_view_interface.py" line="46"/>
<source>Album</source> <source>Album</source>
<translation>專輯</translation> <translation>專輯</translation>
</message> </message>
<message> <message>
<location filename="../../view/navigation_view_interface.py" line="46"/> <location filename="../../view/navigation_view_interface.py" line="47"/>
<source>Artist</source> <source>Artist</source>
<translation>歌手</translation> <translation>歌手</translation>
</message> </message>
...@@ -763,7 +771,7 @@ ...@@ -763,7 +771,7 @@
<message> <message>
<location filename="../../view/scroll_interface.py" line="56"/> <location filename="../../view/scroll_interface.py" line="56"/>
<source>Chitanda Eru is so hot 🥵🥵</source> <source>Chitanda Eru is so hot 🥵🥵</source>
<translation>春寒賜浴華清池泉水滑洗凝脂 🥵🥵</translation> <translation>春寒賜浴華清池泉水滑洗凝脂 🥵🥵</translation>
</message> </message>
<message> <message>
<location filename="../../view/scroll_interface.py" line="67"/> <location filename="../../view/scroll_interface.py" line="67"/>
...@@ -831,7 +839,7 @@ ...@@ -831,7 +839,7 @@
<message> <message>
<location filename="../../view/setting_interface.py" line="85"/> <location filename="../../view/setting_interface.py" line="85"/>
<source>Use system setting</source> <source>Use system setting</source>
<translation>跟隨統設置</translation> <translation>跟隨統設置</translation>
</message> </message>
<message> <message>
<location filename="../../view/setting_interface.py" line="67"/> <location filename="../../view/setting_interface.py" line="67"/>
...@@ -846,7 +854,7 @@ ...@@ -846,7 +854,7 @@
<message> <message>
<location filename="../../view/setting_interface.py" line="74"/> <location filename="../../view/setting_interface.py" line="74"/>
<source>Interface zoom</source> <source>Interface zoom</source>
<translation>縮放</translation> <translation>縮放</translation>
</message> </message>
<message> <message>
<location filename="../../view/setting_interface.py" line="74"/> <location filename="../../view/setting_interface.py" line="74"/>
...@@ -861,7 +869,7 @@ ...@@ -861,7 +869,7 @@
<message> <message>
<location filename="../../view/setting_interface.py" line="85"/> <location filename="../../view/setting_interface.py" line="85"/>
<source>Set your preferred language for UI</source> <source>Set your preferred language for UI</source>
<translation>選擇界所使用的語言</translation> <translation>選擇界所使用的語言</translation>
</message> </message>
<message> <message>
<location filename="../../view/setting_interface.py" line="95"/> <location filename="../../view/setting_interface.py" line="95"/>
...@@ -886,12 +894,12 @@ ...@@ -886,12 +894,12 @@
<message> <message>
<location filename="../../view/setting_interface.py" line="108"/> <location filename="../../view/setting_interface.py" line="108"/>
<source>Check for updates when the application starts</source> <source>Check for updates when the application starts</source>
<translation>在應用程序動時檢查更新</translation> <translation>在應用程序動時檢查更新</translation>
</message> </message>
<message> <message>
<location filename="../../view/setting_interface.py" line="108"/> <location filename="../../view/setting_interface.py" line="108"/>
<source>The new version will be more stable and have more features</source> <source>The new version will be more stable and have more features</source>
<translation>新版本將更加穩定並擁有更多功能建議用此選項</translation> <translation>新版本將更加穩定並擁有更多功能建議用此選項</translation>
</message> </message>
<message> <message>
<location filename="../../view/setting_interface.py" line="134"/> <location filename="../../view/setting_interface.py" line="134"/>
...@@ -901,7 +909,7 @@ ...@@ -901,7 +909,7 @@
<message> <message>
<location filename="../../view/setting_interface.py" line="118"/> <location filename="../../view/setting_interface.py" line="118"/>
<source>Open help page</source> <source>Open help page</source>
<translation>打開幫助頁</translation> <translation>打開幫助頁</translation>
</message> </message>
<message> <message>
<location filename="../../view/setting_interface.py" line="118"/> <location filename="../../view/setting_interface.py" line="118"/>
...@@ -911,7 +919,7 @@ ...@@ -911,7 +919,7 @@
<message> <message>
<location filename="../../view/setting_interface.py" line="118"/> <location filename="../../view/setting_interface.py" line="118"/>
<source>Discover new features and learn useful tips about PyQt-Fluent-Widgets</source> <source>Discover new features and learn useful tips about PyQt-Fluent-Widgets</source>
<translation>發現新功能並瞭解有關 PyQt-Fluent-Widgets 的使用技巧</translation> <translation>髮現新功能並了解有關 PyQt-Fluent-Widgets 的使用技巧</translation>
</message> </message>
<message> <message>
<location filename="../../view/setting_interface.py" line="127"/> <location filename="../../view/setting_interface.py" line="127"/>
...@@ -941,7 +949,7 @@ ...@@ -941,7 +949,7 @@
<message> <message>
<location filename="../../view/setting_interface.py" line="192"/> <location filename="../../view/setting_interface.py" line="192"/>
<source>Configuration takes effect after restart</source> <source>Configuration takes effect after restart</source>
<translation>配置在重軟件後生效</translation> <translation>配置在重軟件後生效</translation>
</message> </message>
<message> <message>
<location filename="../../view/setting_interface.py" line="192"/> <location filename="../../view/setting_interface.py" line="192"/>
...@@ -994,7 +1002,7 @@ ...@@ -994,7 +1002,7 @@
<message> <message>
<location filename="../../view/status_info_interface.py" line="179"/> <location filename="../../view/status_info_interface.py" line="179"/>
<source>Please wait patiently</source> <source>Please wait patiently</source>
<translation>心急吃不了熱請耐心等待哦~</translation> <translation>心急吃不了熱請耐心等待哦~</translation>
</message> </message>
<message> <message>
<location filename="../../view/status_info_interface.py" line="181"/> <location filename="../../view/status_info_interface.py" line="181"/>
...@@ -1059,7 +1067,7 @@ ...@@ -1059,7 +1067,7 @@
<message> <message>
<location filename="../../view/status_info_interface.py" line="75"/> <location filename="../../view/status_info_interface.py" line="75"/>
<source>My name is kira yoshikake, 33 years old. Living in the villa area northeast of duwangting, unmarried. I work in Guiyou chain store. Every day I have to work overtime until 8 p.m. to go home. I don&apos;t smoke. The wine is only for a taste. Sleep at 11 p.m. for 8 hours a day. Before I go to bed, I must drink a cup of warm milk, then do 20 minutes of soft exercise, get on the bed, and immediately fall asleep. Never leave fatigue and stress until the next day. Doctors say I&apos;m normal.</source> <source>My name is kira yoshikake, 33 years old. Living in the villa area northeast of duwangting, unmarried. I work in Guiyou chain store. Every day I have to work overtime until 8 p.m. to go home. I don&apos;t smoke. The wine is only for a taste. Sleep at 11 p.m. for 8 hours a day. Before I go to bed, I must drink a cup of warm milk, then do 20 minutes of soft exercise, get on the bed, and immediately fall asleep. Never leave fatigue and stress until the next day. Doctors say I&apos;m normal.</source>
<translation>我的名字是吉良吉影年齡33歲家住杜王町東北部別墅區未婚我在龜友百貨連鎖公司上班每天最晚也是八點前回家不吸酒也是淺嘗輒止晚上十一點上牀保證八個小時的充足睡眠睡前喝一杯熱牛奶再做二十分鐘伸展運動暖身然後再睡覺基本可以熟睡到天亮像嬰兒一樣不留下疲勞與壓力迎來第二天的早晨健康檢查結果也顯示我很健康我的意思是我是一個隨時都想追求平靜生活的人不拘泥於勝負與煩惱不樹立令我夜不能寐的敵人這就是我對於這個社會的生活態度我也清楚這就是我的幸福</translation> <translation>我的名字是吉良吉影年齡33歲家住杜王町東北部別墅區未婚我在龜友百貨連鎖公司上班每天最晚也是八點前回家不吸酒也是淺嚐輒止晚上十一點上床保証八個小時的充足睡眠睡前喝一盃熱牛奶再做二十分鐘伸展運動暖身然後再睡覺基本可以熟睡到天亮像嬰兒一樣不留下疲勞與壓力迎來第二天的早晨健康檢查結果也顯示我很健康我的意思是我是一個隨時都想追求平靜生活的人不拘泥於勝負與煩惱不樹立令我夜不能寐的敵人這就是我對於這個社會的生活態度我也清楚這就是我的幸福</translation>
</message> </message>
<message> <message>
<location filename="../../view/status_info_interface.py" line="186"/> <location filename="../../view/status_info_interface.py" line="186"/>
...@@ -1069,16 +1077,16 @@ ...@@ -1069,16 +1077,16 @@
<message> <message>
<location filename="../../view/status_info_interface.py" line="186"/> <location filename="../../view/status_info_interface.py" line="186"/>
<source>Believe in the spin, just keep believing!</source> <source>Believe in the spin, just keep believing!</source>
<translation>相信迴旋吧管相信就是了</translation> <translation>相信回旋吧管相信就是了</translation>
</message> </message>
<message> <message>
<location filename="../../view/status_info_interface.py" line="198"/> <location filename="../../view/status_info_interface.py" line="198"/>
<source>With respect, let&apos;s advance towards a new stage of the spin.</source> <source>With respect, let&apos;s advance towards a new stage of the spin.</source>
<translation>表達敬意吧表達出敬意然後邁向旋的另一個全新階段</translation> <translation>表達敬意吧表達出敬意然後邁向旋的另一個全新階段</translation>
</message> </message>
<message> <message>
<location filename="../../view/status_info_interface.py" line="209"/> <location filename="../../view/status_info_interface.py" line="209"/>
<source>路を行けば最短ルート</source> <source>路を行けば最短ルート</source>
<translation>最短的捷徑就是繞遠路繞遠路才是我的最短捷徑</translation> <translation>最短的捷徑就是繞遠路繞遠路才是我的最短捷徑</translation>
</message> </message>
<message> <message>
...@@ -1339,7 +1347,7 @@ ...@@ -1339,7 +1347,7 @@
<message> <message>
<location filename="../../view/view_interface.py" line="108"/> <location filename="../../view/view_interface.py" line="108"/>
<source>Dio Brando</source> <source>Dio Brando</source>
<translation>迪奧·蘭度</translation> <translation>迪奧·蘭度</translation>
</message> </message>
<message> <message>
<location filename="../../view/view_interface.py" line="108"/> <location filename="../../view/view_interface.py" line="108"/>
...@@ -1367,7 +1375,7 @@ ...@@ -1367,7 +1375,7 @@
<message> <message>
<location filename="../../view/view_interface.py" line="46"/> <location filename="../../view/view_interface.py" line="46"/>
<source>A TreeView with Multi-selection enabled</source> <source>A TreeView with Multi-selection enabled</source>
<translation>用複選框的樹狀組件</translation> <translation>用複選框的樹狀組件</translation>
</message> </message>
<message> <message>
<location filename="../../view/view_interface.py" line="31"/> <location filename="../../view/view_interface.py" line="31"/>
......
...@@ -15,12 +15,12 @@ class NavigationViewInterface(GalleryInterface): ...@@ -15,12 +15,12 @@ class NavigationViewInterface(GalleryInterface):
t = Translator() t = Translator()
super().__init__( super().__init__(
title=t.navigation, title=t.navigation,
subtitle="qfluentwidgets.components.widgets", subtitle="qfluentwidgets.components.navigation",
parent=parent parent=parent
) )
self.addExampleCard( self.addExampleCard(
title='A basic pivot', title=self.tr('A basic pivot'),
widget=PivotInterface(self), widget=PivotInterface(self),
sourcePath='https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/pivot/demo.py' sourcePath='https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/pivot/demo.py'
) )
......
...@@ -108,10 +108,10 @@ class Window(FramelessWindow): ...@@ -108,10 +108,10 @@ class Window(FramelessWindow):
self.navigationInterface.addSeparator() self.navigationInterface.addSeparator()
self.addTreeSubInterface(self.albumInterface, FIF.ALBUM, 'Albums') self.addSubInterface(self.albumInterface, FIF.ALBUM, 'Albums', NavigationItemPosition.SCROLL)
self.addTreeSubInterface(self.albumInterface1, FIF.ALBUM, 'Album 1', self.albumInterface) self.addSubInterface(self.albumInterface1, FIF.ALBUM, 'Album 1', parent=self.albumInterface)
self.addTreeSubInterface(self.albumInterface1_1, FIF.ALBUM, 'Album 1.1', self.albumInterface1) self.addSubInterface(self.albumInterface1_1, FIF.ALBUM, 'Album 1.1', parent=self.albumInterface1)
self.addTreeSubInterface(self.albumInterface2, FIF.ALBUM, 'Album 2', self.albumInterface) self.addSubInterface(self.albumInterface2, FIF.ALBUM, 'Album 2', parent=self.albumInterface)
# add navigation items to scroll area # add navigation items to scroll area
self.addSubInterface(self.folderInterface, FIF.FOLDER, 'Folder library', NavigationItemPosition.SCROLL) self.addSubInterface(self.folderInterface, FIF.FOLDER, 'Folder library', NavigationItemPosition.SCROLL)
...@@ -129,7 +129,7 @@ class Window(FramelessWindow): ...@@ -129,7 +129,7 @@ class Window(FramelessWindow):
routeKey='avatar', routeKey='avatar',
widget=AvatarWidget(), widget=AvatarWidget(),
onClick=self.showMessageBox, onClick=self.showMessageBox,
position=NavigationItemPosition.BOTTOM position=NavigationItemPosition.BOTTOM,
) )
self.addSubInterface(self.settingInterface, FIF.SETTING, 'Settings', NavigationItemPosition.BOTTOM) self.addSubInterface(self.settingInterface, FIF.SETTING, 'Settings', NavigationItemPosition.BOTTOM)
...@@ -155,7 +155,7 @@ class Window(FramelessWindow): ...@@ -155,7 +155,7 @@ class Window(FramelessWindow):
self.setQss() self.setQss()
def addSubInterface(self, interface, icon, text: str, position=NavigationItemPosition.TOP): def addSubInterface(self, interface, icon, text: str, position=NavigationItemPosition.TOP, parent=None):
""" add sub interface """ """ add sub interface """
self.stackWidget.addWidget(interface) self.stackWidget.addWidget(interface)
self.navigationInterface.addItem( self.navigationInterface.addItem(
...@@ -164,20 +164,8 @@ class Window(FramelessWindow): ...@@ -164,20 +164,8 @@ class Window(FramelessWindow):
text=text, text=text,
onClick=lambda: self.switchTo(interface), onClick=lambda: self.switchTo(interface),
position=position, position=position,
tooltip=text
)
def addTreeSubInterface(self, interface, icon, text: str, parent=None):
""" add tree sub interface """
self.stackWidget.addWidget(interface)
self.navigationInterface.addTreeItem(
routeKey=interface.objectName(),
icon=icon,
text=text,
onClick=lambda: self.switchTo(interface),
position=NavigationItemPosition.SCROLL,
tooltip=text, tooltip=text,
parentRouteKey=(parent.objectName() if parent else None) parentRouteKey=parent.objectName() if parent else None
) )
def setQss(self): def setQss(self):
...@@ -191,7 +179,7 @@ class Window(FramelessWindow): ...@@ -191,7 +179,7 @@ class Window(FramelessWindow):
def onCurrentInterfaceChanged(self, index): def onCurrentInterfaceChanged(self, index):
widget = self.stackWidget.widget(index) widget = self.stackWidget.widget(index)
self.navigationInterface.setCurrentItem(widget.objectName()) self.navigationInterface.setCurrentItem(widget.objectName())
#!IMPORTANT: This line of code needs to be uncommented if the return button is enabled #!IMPORTANT: This line of code needs to be uncommented if the return button is enabled
# qrouter.push(self.stackWidget, widget.objectName()) # qrouter.push(self.stackWidget, widget.objectName())
......
...@@ -67,7 +67,7 @@ class NavigationBar(QWidget): ...@@ -67,7 +67,7 @@ class NavigationBar(QWidget):
def setCurrentItem(self, routeKey: str): def setCurrentItem(self, routeKey: str):
self.navigationPanel.setCurrentItem(routeKey) self.navigationPanel.setCurrentItem(routeKey)
self.setTitle(self.navigationPanel.items[routeKey]._text) self.setTitle(self.navigationPanel.widget(routeKey).text())
def eventFilter(self, obj, e: QEvent): def eventFilter(self, obj, e: QEvent):
if obj is self.window(): if obj is self.window():
...@@ -122,48 +122,31 @@ class Window(FramelessWindow): ...@@ -122,48 +122,31 @@ class Window(FramelessWindow):
self.vBoxLayout.setStretchFactor(self.stackWidget, 1) self.vBoxLayout.setStretchFactor(self.stackWidget, 1)
def initNavigation(self): def initNavigation(self):
self.navigationInterface.addItem( self.addSubInterface(self.searchInterface, FIF.SEARCH, 'Search')
routeKey=self.searchInterface.objectName(), self.addSubInterface(self.musicInterface, FIF.MUSIC, 'Music library')
icon=FIF.SEARCH, self.addSubInterface(self.videoInterface, FIF.VIDEO, 'Video library')
text='Search',
onClick=lambda: self.switchTo(self.searchInterface)
)
self.navigationInterface.addItem(
routeKey=self.musicInterface.objectName(),
icon=FIF.MUSIC,
text='Music library',
onClick=lambda: self.switchTo(self.musicInterface)
)
self.navigationInterface.addItem(
routeKey=self.videoInterface.objectName(),
icon=FIF.VIDEO,
text='Video library',
onClick=lambda: self.switchTo(self.videoInterface)
)
self.navigationInterface.addSeparator() self.navigationInterface.addSeparator()
# add navigation items to scroll area # add navigation items to scroll area
self.navigationInterface.addItem( self.addSubInterface(self.folderInterface, FIF.FOLDER, 'Folder library', NavigationItemPosition.SCROLL)
routeKey=self.folderInterface.objectName(),
icon=FIF.FOLDER,
text='Folder library',
onClick=lambda: self.switchTo(self.folderInterface),
position=NavigationItemPosition.SCROLL
)
# add custom widget to bottom # add item to bottom
self.navigationInterface.addItem( self.addSubInterface(self.settingInterface, FIF.SETTING, 'Settings', NavigationItemPosition.BOTTOM)
routeKey=self.settingInterface.objectName(),
icon=FIF.SETTING,
text='Settings',
onClick=lambda: self.switchTo(self.settingInterface),
position=NavigationItemPosition.BOTTOM
)
self.stackWidget.currentChanged.connect(self.onCurrentInterfaceChanged) self.stackWidget.currentChanged.connect(self.onCurrentInterfaceChanged)
self.stackWidget.setCurrentIndex(1) self.stackWidget.setCurrentIndex(1)
def addSubInterface(self, w: QWidget, icon, text, position=NavigationItemPosition.TOP):
self.stackWidget.addWidget(w)
self.navigationInterface.addItem(
routeKey=w.objectName(),
icon=icon,
text=text,
onClick=lambda: self.switchTo(w),
position=position
)
def initWindow(self): def initWindow(self):
self.resize(500, 600) self.resize(500, 600)
self.setWindowIcon(QIcon('resource/logo.png')) self.setWindowIcon(QIcon('resource/logo.png'))
......
...@@ -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.9.0" __version__ = "0.9.1"
from .components import * from .components import *
from .common import * from .common import *
......
...@@ -4,7 +4,7 @@ PushButton, ToolButton, ToggleButton { ...@@ -4,7 +4,7 @@ PushButton, ToolButton, ToggleButton {
border-top: 1px solid rgba(255, 255, 255, 0.08); border-top: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 5px; border-radius: 5px;
color: white; color: white;
font: 14px 'Segoe UI', 'Microsoft YaHei'; /* font: 14px 'Segoe UI', 'Microsoft YaHei'; */
padding: 5px 12px 6px 12px; padding: 5px 12px 6px 12px;
outline: none; outline: none;
} }
...@@ -120,7 +120,7 @@ PrimarySplitDropButton { ...@@ -120,7 +120,7 @@ PrimarySplitDropButton {
} }
HyperlinkButton { HyperlinkButton {
font: 14px 'Segoe UI', 'Microsoft YaHei'; /* font: 14px 'Segoe UI', 'Microsoft YaHei'; */
padding: 5px 12px 6px 12px; padding: 5px 12px 6px 12px;
color: --ThemeColorPrimary; color: --ThemeColorPrimary;
border: none; border: none;
......
...@@ -3,7 +3,7 @@ LineEdit, TextEdit, PlainTextEdit { ...@@ -3,7 +3,7 @@ LineEdit, TextEdit, PlainTextEdit {
border: 1px solid rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.08);
border-bottom: 1px solid rgba(255, 255, 255, 0.5442); border-bottom: 1px solid rgba(255, 255, 255, 0.5442);
border-radius: 5px; border-radius: 5px;
font: 14px "Segoe UI", "Microsoft YaHei"; /* font: 14px "Segoe UI", "Microsoft YaHei"; */
padding: 0px 10px; padding: 0px 10px;
color: white; color: white;
selection-background-color: --ThemeColorPrimary; selection-background-color: --ThemeColorPrimary;
......
...@@ -3,7 +3,7 @@ ListWidget { ...@@ -3,7 +3,7 @@ ListWidget {
background: transparent; background: transparent;
outline: none; outline: none;
border: none; border: none;
font: 13px 'Segoe UI', 'Microsoft YaHei'; /* font: 13px 'Segoe UI', 'Microsoft YaHei'; */
selection-background-color: transparent; selection-background-color: transparent;
alternate-background-color: transparent; alternate-background-color: transparent;
padding-left: 4px; padding-left: 4px;
......
...@@ -7,7 +7,7 @@ TimeEdit { ...@@ -7,7 +7,7 @@ TimeEdit {
border: 1px solid rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.08);
border-bottom: 1px solid rgba(255, 255, 255, 0.5442); border-bottom: 1px solid rgba(255, 255, 255, 0.5442);
border-radius: 5px; border-radius: 5px;
font: 14px "Segoe UI", "Microsoft YaHei"; /* font: 14px "Segoe UI", "Microsoft YaHei"; */
padding: 0px 80px 0 10px; padding: 0px 80px 0 10px;
color: white; color: white;
selection-background-color: --ThemeColorPrimary; selection-background-color: --ThemeColorPrimary;
......
...@@ -2,7 +2,7 @@ QTableView { ...@@ -2,7 +2,7 @@ QTableView {
background: transparent; background: transparent;
outline: none; outline: none;
border: none; border: none;
font: 13px 'Segoe UI', 'Microsoft YaHei'; /* font: 13px 'Segoe UI', 'Microsoft YaHei'; */
selection-background-color: transparent; selection-background-color: transparent;
alternate-background-color: transparent; alternate-background-color: transparent;
} }
......
...@@ -4,7 +4,7 @@ QTreeView { ...@@ -4,7 +4,7 @@ QTreeView {
border-radius: 5px; border-radius: 5px;
outline: 0; outline: 0;
padding-right: 5px; padding-right: 5px;
font: 13px 'Segoe UI', 'Microsoft YaHei'; /* font: 13px 'Segoe UI', 'Microsoft YaHei'; */
selection-background-color: transparent; selection-background-color: transparent;
} }
......
...@@ -4,7 +4,7 @@ PushButton, ToolButton, ToggleButton { ...@@ -4,7 +4,7 @@ PushButton, ToolButton, ToggleButton {
border: 1px solid rgba(0, 0, 0, 0.073); border: 1px solid rgba(0, 0, 0, 0.073);
border-bottom: 1px solid rgba(0, 0, 0, 0.183); border-bottom: 1px solid rgba(0, 0, 0, 0.183);
border-radius: 5px; border-radius: 5px;
font: 14px 'Segoe UI', 'Microsoft YaHei'; /* font: 14px 'Segoe UI', 'Microsoft YaHei'; */
padding: 5px 12px 6px 12px; padding: 5px 12px 6px 12px;
outline: none; outline: none;
} }
...@@ -120,7 +120,7 @@ PrimarySplitDropButton:pressed { ...@@ -120,7 +120,7 @@ PrimarySplitDropButton:pressed {
} }
HyperlinkButton { HyperlinkButton {
font: 14px 'Segoe UI', 'Microsoft YaHei'; /* font: 14px 'Segoe UI', 'Microsoft YaHei'; */
padding: 6px 12px 6px 12px; padding: 6px 12px 6px 12px;
color: --ThemeColorPrimary; color: --ThemeColorPrimary;
border: none; border: none;
......
...@@ -4,7 +4,7 @@ LineEdit, TextEdit, PlainTextEdit { ...@@ -4,7 +4,7 @@ LineEdit, TextEdit, PlainTextEdit {
border: 1px solid rgba(0, 0, 0, 13); border: 1px solid rgba(0, 0, 0, 13);
border-bottom: 1px solid rgba(0, 0, 0, 100); border-bottom: 1px solid rgba(0, 0, 0, 100);
border-radius: 5px; border-radius: 5px;
font: 14px "Segoe UI", "Microsoft YaHei"; /* font: 14px "Segoe UI", "Microsoft YaHei"; */
padding: 0px 10px; padding: 0px 10px;
selection-background-color: --ThemeColorLight1; selection-background-color: --ThemeColorLight1;
} }
......
...@@ -3,7 +3,7 @@ ListWidget { ...@@ -3,7 +3,7 @@ ListWidget {
background: transparent; background: transparent;
outline: none; outline: none;
border: none; border: none;
font: 13px 'Segoe UI', 'Microsoft YaHei'; /* font: 13px 'Segoe UI', 'Microsoft YaHei'; */
selection-background-color: transparent; selection-background-color: transparent;
alternate-background-color: transparent; alternate-background-color: transparent;
padding-left: 4px; padding-left: 4px;
......
...@@ -4,7 +4,7 @@ SpinBox, DoubleSpinBox, DateEdit, DateTimeEdit, TimeEdit { ...@@ -4,7 +4,7 @@ SpinBox, DoubleSpinBox, DateEdit, DateTimeEdit, TimeEdit {
border: 1px solid rgba(0, 0, 0, 13); border: 1px solid rgba(0, 0, 0, 13);
border-bottom: 1px solid rgba(0, 0, 0, 100); border-bottom: 1px solid rgba(0, 0, 0, 100);
border-radius: 5px; border-radius: 5px;
font: 14px "Segoe UI", "Microsoft YaHei"; /* font: 14px "Segoe UI", "Microsoft YaHei"; */
padding: 0px 80px 0 10px; padding: 0px 80px 0 10px;
selection-background-color: --ThemeColorLight1; selection-background-color: --ThemeColorLight1;
} }
......
...@@ -2,7 +2,7 @@ QTableView { ...@@ -2,7 +2,7 @@ QTableView {
background: transparent; background: transparent;
outline: none; outline: none;
border: none; border: none;
font: 13px 'Segoe UI', 'Microsoft YaHei'; /* font: 13px 'Segoe UI', 'Microsoft YaHei'; */
selection-background-color: transparent; selection-background-color: transparent;
alternate-background-color: transparent; alternate-background-color: transparent;
} }
......
...@@ -4,7 +4,7 @@ QTreeView { ...@@ -4,7 +4,7 @@ QTreeView {
border-radius: 5px; border-radius: 5px;
outline: 0; outline: 0;
padding-right: 5px; padding-right: 5px;
font: 13px 'Segoe UI', 'Microsoft YaHei'; /* font: 13px 'Segoe UI', 'Microsoft YaHei'; */
selection-background-color: transparent; selection-background-color: transparent;
} }
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
from .config import * from .config import *
from .font import setFont, getFont
from .auto_wrap import TextWrap from .auto_wrap import TextWrap
from .icon import Action, Icon, getIconColor, drawSvgIcon, FluentIcon, drawIcon, FluentIconBase, writeSvg from .icon import Action, Icon, getIconColor, drawSvgIcon, FluentIcon, drawIcon, FluentIconBase, writeSvg
from .style_sheet import (setStyleSheet, getStyleSheet, setTheme, ThemeColor, themeColor, from .style_sheet import (setStyleSheet, getStyleSheet, setTheme, ThemeColor, themeColor,
......
# coding: utf-8
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QWidget
def setFont(widget: QWidget, fontSize=14):
""" set the font of widget
Parameters
----------
widget: QWidget
the widget to set font
fontSize: int
font pixel size
"""
widget.setFont(getFont(fontSize))
def getFont(fontSize=14):
""" create font
Parameters
----------
fontSize: int
font pixel size
"""
font = QFont()
font.setFamilies(['Segoe UI', 'Microsoft YaHei'])
font.setPixelSize(fontSize)
return font
\ No newline at end of file
from .navigation_widget import NavigationWidget, NavigationPushButton, NavigationSeparator, NavigationToolButton from .navigation_widget import (NavigationWidget, NavigationPushButton, NavigationSeparator, NavigationToolButton,
NavigationTreeWidget, NavigationTreeWidgetBase)
from .navigation_panel import NavigationPanel, NavigationItemPosition, NavigationDisplayMode from .navigation_panel import NavigationPanel, NavigationItemPosition, NavigationDisplayMode
from .navigation_interface import NavigationInterface from .navigation_interface import NavigationInterface
from .pivot import Pivot, PivotItem from .pivot import Pivot, PivotItem
\ No newline at end of file
...@@ -6,7 +6,7 @@ from PyQt5.QtGui import QResizeEvent, QIcon ...@@ -6,7 +6,7 @@ from PyQt5.QtGui import QResizeEvent, QIcon
from PyQt5.QtWidgets import QWidget from PyQt5.QtWidgets import QWidget
from .navigation_panel import NavigationPanel, NavigationItemPosition, NavigationWidget, NavigationDisplayMode from .navigation_panel import NavigationPanel, NavigationItemPosition, NavigationWidget, NavigationDisplayMode
from .navigation_widget import NavigationPushButton from .navigation_widget import NavigationTreeWidget
from ...common.style_sheet import FluentStyleSheet from ...common.style_sheet import FluentStyleSheet
from ...common.icon import FluentIconBase from ...common.icon import FluentIconBase
...@@ -41,8 +41,9 @@ class NavigationInterface(QWidget): ...@@ -41,8 +41,9 @@ class NavigationInterface(QWidget):
self.setAttribute(Qt.WA_StyledBackground) self.setAttribute(Qt.WA_StyledBackground)
FluentStyleSheet.NAVIGATION_INTERFACE.apply(self) FluentStyleSheet.NAVIGATION_INTERFACE.apply(self)
def addItem(self, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None, selectable=True, def addItem(self, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None,
position=NavigationItemPosition.TOP, tooltip: str = None) -> NavigationPushButton: selectable=True, position=NavigationItemPosition.TOP, tooltip: str = None,
parentRouteKey: str = None) -> NavigationTreeWidget:
""" add navigation item """ add navigation item
Parameters Parameters
...@@ -65,45 +66,16 @@ class NavigationInterface(QWidget): ...@@ -65,45 +66,16 @@ class NavigationInterface(QWidget):
position: NavigationItemPosition position: NavigationItemPosition
where the button is added where the button is added
tooltip: str
the tooltip of item
"""
return self.insertItem(-1, routeKey, icon, text, onClick, selectable, position, tooltip)
def addTreeItem(self, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None,
selectable=True, position=NavigationItemPosition.SCROLL, tooltip: str = None, parentRouteKey=None):
""" add navigation tree item
Parameters
----------
routeKey: str
the unique name of item
icon: str | QIcon | FluentIconBase
the icon of navigation item
text: str
the text of navigation item
onClick: callable
the slot connected to item clicked signal
position: NavigationItemPosition
where the button is added
selectable: bool
whether the item is selectable
tooltip: str tooltip: str
the tooltip of item the tooltip of item
parentRouteKey: str parentRouteKey: str
the route key of parent item the route key of parent item, the parent item should be `NavigationTreeWidgetBase`
""" """
return self.insertTreeItem(-1, routeKey, icon, text, onClick, selectable, position, tooltip, parentRouteKey) return self.insertItem(-1, routeKey, icon, text, onClick, selectable, position, tooltip, parentRouteKey)
def addWidget(self, routeKey: str, widget: NavigationWidget, onClick=None, position=NavigationItemPosition.TOP, def addWidget(self, routeKey: str, widget: NavigationWidget, onClick=None, position=NavigationItemPosition.TOP,
tooltip: str = None): tooltip: str = None, parentRouteKey: str = None):
""" add custom widget """ add custom widget
Parameters Parameters
...@@ -118,15 +90,19 @@ class NavigationInterface(QWidget): ...@@ -118,15 +90,19 @@ class NavigationInterface(QWidget):
the slot connected to item clicked signal the slot connected to item clicked signal
position: NavigationItemPosition position: NavigationItemPosition
where the button is added where the widget is added
tooltip: str tooltip: str
the tooltip of widget the tooltip of widget
parentRouteKey: str
the route key of parent item, the parent item should be `NavigationTreeWidgetBase`
""" """
self.insertWidget(-1, routeKey, widget, onClick, position, tooltip) self.insertWidget(-1, routeKey, widget, onClick, position, tooltip, parentRouteKey)
def insertItem(self, index: int, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None, def insertItem(self, index: int, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str,
selectable=True, position=NavigationItemPosition.TOP, tooltip: str = None) -> NavigationPushButton: onClick=None, selectable=True, position=NavigationItemPosition.TOP, tooltip: str = None,
parentRouteKey: str = None) -> NavigationTreeWidget:
""" insert navigation item """ insert navigation item
Parameters Parameters
...@@ -150,55 +126,20 @@ class NavigationInterface(QWidget): ...@@ -150,55 +126,20 @@ class NavigationInterface(QWidget):
whether the item is selectable whether the item is selectable
position: NavigationItemPosition position: NavigationItemPosition
where the button is added where the item is added
tooltip: str
the tooltip of item
"""
button = self.panel.insertItem(index, routeKey, icon, text, onClick, selectable, position, tooltip)
self.setMinimumHeight(self.panel.layoutMinHeight())
return button
def insertTreeItem(self, index: int, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None,
selectable=True, position=NavigationItemPosition.SCROLL, tooltip: str = None, parentRouteKey=None):
""" insert navigation tree item
Parameters
----------
index: int
the insert position of parent widget
routeKey: str
the unique name of item
icon: str | QIcon | FluentIconBase
the icon of navigation item
text: str
the text of navigation item
onClick: callable
the slot connected to item clicked signal
position: NavigationItemPosition
where the button is added
selectable: bool
whether the item is selectable
tooltip: str tooltip: str
the tooltip of item the tooltip of item
parentRouteKey: str parentRouteKey: str
the route key of parent item the route key of parent item, the parent item should be `NavigationTreeWidgetBase`
""" """
button = self.panel.insertTreeItem( w = self.panel.insertItem(index, routeKey, icon, text, onClick, selectable, position, tooltip, parentRouteKey)
index, routeKey, icon, text, onClick, selectable, position, tooltip, parentRouteKey)
self.setMinimumHeight(self.panel.layoutMinHeight()) self.setMinimumHeight(self.panel.layoutMinHeight())
return button return w
def insertWidget(self, index: int, routeKey: str, widget: NavigationWidget, onClick=None, def insertWidget(self, index: int, routeKey: str, widget: NavigationWidget, onClick=None,
position=NavigationItemPosition.TOP, tooltip: str = None): position=NavigationItemPosition.TOP, tooltip: str = None, parentRouteKey: str = None):
""" insert custom widget """ insert custom widget
Parameters Parameters
...@@ -216,12 +157,15 @@ class NavigationInterface(QWidget): ...@@ -216,12 +157,15 @@ class NavigationInterface(QWidget):
the slot connected to item clicked signal the slot connected to item clicked signal
position: NavigationItemPosition position: NavigationItemPosition
where the button is added where the widget is added
tooltip: str tooltip: str
the tooltip of widget the tooltip of widget
parentRouteKey: str
the route key of parent item, the parent item should be `NavigationTreeWidgetBase`
""" """
self.panel.insertWidget(index, routeKey, widget, onClick, position, tooltip) self.panel.insertWidget(index, routeKey, widget, onClick, position, tooltip, parentRouteKey)
self.setMinimumHeight(self.panel.layoutMinHeight()) self.setMinimumHeight(self.panel.layoutMinHeight())
def addSeparator(self, position=NavigationItemPosition.TOP): def addSeparator(self, position=NavigationItemPosition.TOP):
...@@ -276,6 +220,9 @@ class NavigationInterface(QWidget): ...@@ -276,6 +220,9 @@ class NavigationInterface(QWidget):
""" set the maximum width """ """ set the maximum width """
self.panel.setExpandWidth(width) self.panel.setExpandWidth(width)
def widget(self, routeKey: str):
return self.panel.widget(routeKey)
def eventFilter(self, obj, e: QEvent): def eventFilter(self, obj, e: QEvent):
if obj is not self.panel or e.type() != QEvent.Resize: if obj is not self.panel or e.type() != QEvent.Resize:
return super().eventFilter(obj, e) return super().eventFilter(obj, e)
......
...@@ -6,7 +6,7 @@ from PyQt5.QtCore import Qt, QPropertyAnimation, QRect, QSize, QEvent, QEasingCu ...@@ -6,7 +6,7 @@ from PyQt5.QtCore import Qt, QPropertyAnimation, QRect, QSize, QEvent, QEasingCu
from PyQt5.QtGui import QResizeEvent, QIcon from PyQt5.QtGui import QResizeEvent, QIcon
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QFrame, QApplication from PyQt5.QtWidgets import QWidget, QVBoxLayout, QFrame, QApplication
from .navigation_widget import (NavigationPushButton, NavigationToolButton, NavigationWidget, NavigationSeparator, from .navigation_widget import (NavigationTreeWidgetBase, NavigationToolButton, NavigationWidget, NavigationSeparator,
NavigationTreeWidget) NavigationTreeWidget)
from ..widgets.scroll_area import SingleDirectionScrollArea from ..widgets.scroll_area import SingleDirectionScrollArea
from ..widgets.tool_tip import ToolTipFilter from ..widgets.tool_tip import ToolTipFilter
...@@ -45,6 +45,14 @@ class RouteKeyError(Exception): ...@@ -45,6 +45,14 @@ class RouteKeyError(Exception):
""" Route key error """ """ Route key error """
class NavigationItem:
""" Navigation item """
def __init__(self, routeKey: str, parentRouteKey: str, widget: NavigationWidget):
self.routeKey = routeKey
self.parentRouteKey = parentRouteKey
self.widget = widget
class NavigationPanel(QFrame): class NavigationPanel(QFrame):
""" Navigation panel """ """ Navigation panel """
...@@ -68,7 +76,7 @@ class NavigationPanel(QFrame): ...@@ -68,7 +76,7 @@ class NavigationPanel(QFrame):
self.bottomLayout = NavigationItemLayout() self.bottomLayout = NavigationItemLayout()
self.scrollLayout = NavigationItemLayout(self.scrollWidget) self.scrollLayout = NavigationItemLayout(self.scrollWidget)
self.items = {} # type: Dict[str, NavigationWidget] self.items = {} # type: Dict[str, NavigationItem]
self.history = qrouter self.history = qrouter
self.expandAni = QPropertyAnimation(self, b'geometry', self) self.expandAni = QPropertyAnimation(self, b'geometry', self)
...@@ -141,10 +149,10 @@ class NavigationPanel(QFrame): ...@@ -141,10 +149,10 @@ class NavigationPanel(QFrame):
if routeKey not in self.items: if routeKey not in self.items:
raise RouteKeyError(f"`{routeKey}` is illegal.") raise RouteKeyError(f"`{routeKey}` is illegal.")
return self.items[routeKey] return self.items[routeKey].widget
def addItem(self, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None, selectable=True, def addItem(self, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None, selectable=True,
position=NavigationItemPosition.TOP, tooltip: str = None): position=NavigationItemPosition.TOP, tooltip: str = None, parentRouteKey: str = None):
""" add navigation item """ add navigation item
Parameters Parameters
...@@ -169,11 +177,14 @@ class NavigationPanel(QFrame): ...@@ -169,11 +177,14 @@ class NavigationPanel(QFrame):
tooltip: str tooltip: str
the tooltip of item the tooltip of item
parentRouteKey: str
the route key of parent item, the parent widget should be `NavigationTreeWidget`
""" """
return self.insertItem(-1, routeKey, icon, text, onClick, selectable, position, tooltip) return self.insertItem(-1, routeKey, icon, text, onClick, selectable, position, tooltip, parentRouteKey)
def addWidget(self, routeKey: str, widget: NavigationWidget, onClick=None, position=NavigationItemPosition.TOP, def addWidget(self, routeKey: str, widget: NavigationWidget, onClick=None, position=NavigationItemPosition.TOP,
tooltip: str = None): tooltip: str = None, parentRouteKey: str = None):
""" add custom widget """ add custom widget
Parameters Parameters
...@@ -192,81 +203,14 @@ class NavigationPanel(QFrame): ...@@ -192,81 +203,14 @@ class NavigationPanel(QFrame):
tooltip: str tooltip: str
the tooltip of widget the tooltip of widget
"""
self.insertWidget(-1, routeKey, widget, onClick, position, tooltip)
def insertItem(self, index: int, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None,
selectable=True, position=NavigationItemPosition.TOP, tooltip: str = None):
""" insert navigation item
Parameters
----------
index: int
insert position
routeKey: str
the unique name of item
icon: str | QIcon | FluentIconBase
the icon of navigation item
text: str
the text of navigation item
onClick: callable
the slot connected to item clicked signal
position: NavigationItemPosition
where the button is added
selectable: bool
whether the item is selectable
tooltip: str
the tooltip of item
"""
if routeKey in self.items:
return
button = NavigationPushButton(icon, text, selectable, self)
self.insertWidget(index, routeKey, button, onClick, position, tooltip)
return button
def addTreeItem(self, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None,
selectable=True, position=NavigationItemPosition.SCROLL, tooltip: str = None, parentRouteKey=None):
""" add navigation tree item
Parameters
----------
routeKey: str
the unique name of item
icon: str | QIcon | FluentIconBase
the icon of navigation item
text: str
the text of navigation item
onClick: callable
the slot connected to item clicked signal
position: NavigationItemPosition
where the button is added
selectable: bool
whether the item is selectable
tooltip: str
the tooltip of item
parentRouteKey: str parentRouteKey: str
the route key of parent item the route key of parent item, the parent item should be `NavigationTreeWidget`
""" """
return self.insertTreeItem(-1, routeKey, icon, text, onClick, selectable, position, tooltip, parentRouteKey) self.insertWidget(-1, routeKey, widget, onClick, position, tooltip, parentRouteKey)
def insertTreeItem(self, index: int, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None, def insertItem(self, index: int, routeKey: str, icon: Union[str, QIcon, FluentIconBase], text: str, onClick=None,
selectable=True, position=NavigationItemPosition.SCROLL, tooltip: str = None, parentRouteKey=None): selectable=True, position=NavigationItemPosition.TOP, tooltip: str = None, parentRouteKey=None):
""" insert navigation tree item """ insert navigation tree item
Parameters Parameters
...@@ -296,22 +240,17 @@ class NavigationPanel(QFrame): ...@@ -296,22 +240,17 @@ class NavigationPanel(QFrame):
the tooltip of item the tooltip of item
parentRouteKey: str parentRouteKey: str
the route key of parent item the route key of parent item, the parent item should be `NavigationTreeWidget`
""" """
if routeKey in self.items: if routeKey in self.items:
return return
w = NavigationTreeWidget(icon, text, selectable, self) w = NavigationTreeWidget(icon, text, selectable, self)
if parentRouteKey: self.insertWidget(index, routeKey, w, onClick, position, tooltip, parentRouteKey)
self._registerWidget(routeKey, w, onClick, tooltip)
self.widget(parentRouteKey).insertChild(index, w)
else:
self.insertWidget(index, routeKey, w, onClick, position, tooltip)
return w return w
def insertWidget(self, index: int, routeKey: str, widget: NavigationWidget, onClick=None, def insertWidget(self, index: int, routeKey: str, widget: NavigationWidget, onClick=None,
position=NavigationItemPosition.TOP, tooltip: str = None): position=NavigationItemPosition.TOP, tooltip: str = None, parentRouteKey: str = None):
""" insert custom widget """ insert custom widget
Parameters Parameters
...@@ -333,12 +272,18 @@ class NavigationPanel(QFrame): ...@@ -333,12 +272,18 @@ class NavigationPanel(QFrame):
tooltip: str tooltip: str
the tooltip of widget the tooltip of widget
parentRouteKey: str
the route key of parent item, the parent item should be `NavigationTreeWidget`
""" """
if routeKey in self.items: if routeKey in self.items:
return return
self._registerWidget(routeKey, widget, onClick, tooltip) self._registerWidget(routeKey, parentRouteKey, widget, onClick, tooltip)
self._insertWidgetToLayout(index, widget, position) if parentRouteKey:
self.widget(parentRouteKey).insertChild(index, widget)
else:
self._insertWidgetToLayout(index, widget, position)
def addSeparator(self, position=NavigationItemPosition.TOP): def addSeparator(self, position=NavigationItemPosition.TOP):
""" add separator """ add separator
...@@ -364,7 +309,7 @@ class NavigationPanel(QFrame): ...@@ -364,7 +309,7 @@ class NavigationPanel(QFrame):
separator = NavigationSeparator(self) separator = NavigationSeparator(self)
self._insertWidgetToLayout(index, separator, position) self._insertWidgetToLayout(index, separator, position)
def _registerWidget(self, routeKey: str, widget: NavigationWidget, onClick, tooltip: str): def _registerWidget(self, routeKey: str, parentRouteKey: str, widget: NavigationWidget, onClick, tooltip: str):
""" register widget """ """ register widget """
widget.clicked.connect(self._onWidgetClicked) widget.clicked.connect(self._onWidgetClicked)
...@@ -372,7 +317,8 @@ class NavigationPanel(QFrame): ...@@ -372,7 +317,8 @@ class NavigationPanel(QFrame):
widget.clicked.connect(onClick) widget.clicked.connect(onClick)
widget.setProperty('routeKey', routeKey) widget.setProperty('routeKey', routeKey)
self.items[routeKey] = widget widget.setProperty('parentRouteKey', parentRouteKey)
self.items[routeKey] = NavigationItem(routeKey, parentRouteKey, widget)
if self.displayMode in [NavigationDisplayMode.EXPAND, NavigationDisplayMode.MENU]: if self.displayMode in [NavigationDisplayMode.EXPAND, NavigationDisplayMode.MENU]:
widget.setCompacted(False) widget.setCompacted(False)
...@@ -406,8 +352,12 @@ class NavigationPanel(QFrame): ...@@ -406,8 +352,12 @@ class NavigationPanel(QFrame):
if routeKey not in self.items: if routeKey not in self.items:
return return
w = self.items.pop(routeKey) item = self.items.pop(routeKey)
w.deleteLater()
if item.parentRouteKey is not None:
self.widget(item.parentRouteKey).removeChild(item.widget)
item.widget.deleteLater()
self.history.remove(routeKey) self.history.remove(routeKey)
def setMenuButtonVisible(self, isVisible: bool): def setMenuButtonVisible(self, isVisible: bool):
...@@ -462,9 +412,10 @@ class NavigationPanel(QFrame): ...@@ -462,9 +412,10 @@ class NavigationPanel(QFrame):
if self.expandAni.state() == QPropertyAnimation.Running: if self.expandAni.state() == QPropertyAnimation.Running:
return return
for w in self.items.values(): for item in self.items.values():
if isinstance(w, NavigationTreeWidget) and w.isRoot(): w = item.widget
w.setExpanded(False, ani=False) if isinstance(w, NavigationTreeWidgetBase) and w.isRoot():
w.setExpanded(False)
self.expandAni.setStartValue( self.expandAni.setStartValue(
QRect(self.pos(), QSize(self.width(), self.height()))) QRect(self.pos(), QSize(self.width(), self.height())))
...@@ -494,7 +445,7 @@ class NavigationPanel(QFrame): ...@@ -494,7 +445,7 @@ class NavigationPanel(QFrame):
return return
for k, item in self.items.items(): for k, item in self.items.items():
item.setSelected(k == routeKey) item.widget.setSelected(k == routeKey)
def _onWidgetClicked(self): def _onWidgetClicked(self):
widget = self.sender() # type: NavigationWidget widget = self.sender() # type: NavigationWidget
...@@ -503,7 +454,7 @@ class NavigationPanel(QFrame): ...@@ -503,7 +454,7 @@ class NavigationPanel(QFrame):
self.setCurrentItem(widget.property('routeKey')) self.setCurrentItem(widget.property('routeKey'))
if widget is not self.menuButton and self.displayMode == NavigationDisplayMode.MENU \ if widget is not self.menuButton and self.displayMode == NavigationDisplayMode.MENU \
and not isinstance(widget, NavigationTreeWidget): and not (isinstance(widget, NavigationTreeWidgetBase) and not widget.isLeaf()):
self.collapse() self.collapse()
def resizeEvent(self, e: QResizeEvent): def resizeEvent(self, e: QResizeEvent):
...@@ -550,7 +501,7 @@ class NavigationPanel(QFrame): ...@@ -550,7 +501,7 @@ class NavigationPanel(QFrame):
self.setStyle(QApplication.style()) self.setStyle(QApplication.style())
for item in self.items.values(): for item in self.items.values():
item.setCompacted(True) item.widget.setCompacted(True)
if not self._parent.isWindow(): if not self._parent.isWindow():
self.setParent(self._parent) self.setParent(self._parent)
......
# coding:utf-8 # coding:utf-8
from typing import Union, List from typing import Union, List
from PyQt5.QtCore import Qt, pyqtSignal, QRect, QRectF, QPropertyAnimation, pyqtProperty, QMargins, QEasingCurve, QPoint from PyQt5.QtCore import (Qt, pyqtSignal, QRect, QRectF, QPropertyAnimation, pyqtProperty, QMargins,
QEasingCurve, QPoint, QEvent)
from PyQt5.QtGui import QColor, QPainter, QPen, QIcon, QCursor from PyQt5.QtGui import QColor, QPainter, QPen, QIcon, QCursor
from PyQt5.QtWidgets import QWidget, QVBoxLayout from PyQt5.QtWidgets import QWidget, QVBoxLayout
...@@ -24,6 +25,8 @@ class NavigationWidget(QWidget): ...@@ -24,6 +25,8 @@ class NavigationWidget(QWidget):
self.isPressed = False self.isPressed = False
self.isEnter = False self.isEnter = False
self.isSelectable = isSelectable self.isSelectable = isSelectable
self.treeParent = None
self.nodeDepth = 0
self.setFixedSize(40, 36) self.setFixedSize(40, 36)
def enterEvent(self, e): def enterEvent(self, e):
...@@ -65,7 +68,7 @@ class NavigationWidget(QWidget): ...@@ -65,7 +68,7 @@ class NavigationWidget(QWidget):
isSelected: bool isSelected: bool
whether the button is selected whether the button is selected
""" """
if not self.isSelectable or self.isSelected == isSelected: if not self.isSelectable:
return return
self.isSelected = isSelected self.isSelected = isSelected
...@@ -241,15 +244,65 @@ class NavigationTreeItem(NavigationPushButton): ...@@ -241,15 +244,65 @@ class NavigationTreeItem(NavigationPushButton):
arrowAngle = pyqtProperty(float, getArrowAngle, setArrowAngle) arrowAngle = pyqtProperty(float, getArrowAngle, setArrowAngle)
class NavigationTreeWidget(NavigationWidget): class NavigationTreeWidgetBase(NavigationWidget):
""" Navigation tree widget base class """
def addChild(self, child):
""" add child
Parameters
----------
child: NavigationTreeWidgetBase
child item
"""
raise NotImplementedError
def insertChild(self, index: int, child: NavigationWidget):
""" insert child
Parameters
----------
child: NavigationTreeWidgetBase
child item
"""
raise NotImplementedError
def removeChild(self, child: NavigationWidget):
""" remove child
Parameters
----------
child: NavigationTreeWidgetBase
child item
"""
raise NotImplementedError
def isRoot(self):
""" is root node """
return True
def isLeaf(self):
""" is leaf node """
return True
def setExpanded(self, isExpanded: bool):
""" set the expanded status
Parameters
----------
isExpanded: bool
whether to expand node
"""
raise NotImplementedError
class NavigationTreeWidget(NavigationTreeWidgetBase):
""" Navigation tree widget """ """ Navigation tree widget """
def __init__(self, icon: Union[str, QIcon, FIF], text: str, isSelectable: bool, parent=None): def __init__(self, icon: Union[str, QIcon, FIF], text: str, isSelectable: bool, parent=None):
super().__init__(isSelectable, parent) super().__init__(isSelectable, parent)
self.treeChildren = [] # type: List[NavigationTreeWidget] self.treeChildren = [] # type: List[NavigationTreeWidget]
self.treeParent = None # type: NavigationTreeWidget
self.nodeDepth = 0
self.isExpanded = False self.isExpanded = False
self.itemWidget = NavigationTreeItem(icon, text, isSelectable, self) self.itemWidget = NavigationTreeItem(icon, text, isSelectable, self)
...@@ -267,27 +320,13 @@ class NavigationTreeWidget(NavigationWidget): ...@@ -267,27 +320,13 @@ class NavigationTreeWidget(NavigationWidget):
self.setAttribute(Qt.WA_TranslucentBackground) self.setAttribute(Qt.WA_TranslucentBackground)
self.expandAni.valueChanged.connect(lambda g: self.setFixedSize(g.size())) self.expandAni.valueChanged.connect(lambda g: self.setFixedSize(g.size()))
def addChild(self, child: 'NavigationTreeWidget'): def addChild(self, child):
""" add child
Parameters
----------
child: NavigationTreeWidget
child item
"""
self.insertChild(-1, child) self.insertChild(-1, child)
def text(self): def text(self):
return self.itemWidget.text() return self.itemWidget.text()
def insertChild(self, index: int, child: 'NavigationTreeWidget'): def insertChild(self, index, child):
""" insert child
Parameters
----------
child: NavigationTreeWidget
child item
"""
if child in self.treeChildren: if child in self.treeChildren:
return return
...@@ -303,7 +342,11 @@ class NavigationTreeWidget(NavigationWidget): ...@@ -303,7 +342,11 @@ class NavigationTreeWidget(NavigationWidget):
self.treeChildren.insert(index, child) self.treeChildren.insert(index, child)
self.vBoxLayout.insertWidget(index, child, 0, Qt.AlignTop) self.vBoxLayout.insertWidget(index, child, 0, Qt.AlignTop)
def setExpanded(self, isExpanded: bool, ani=True): def removeChild(self, child):
self.treeChildren.remove(child)
self.vBoxLayout.removeWidget(child)
def setExpanded(self, isExpanded: bool, ani=False):
""" set the expanded status """ """ set the expanded status """
if isExpanded == self.isExpanded: if isExpanded == self.isExpanded:
return return
...@@ -345,9 +388,9 @@ class NavigationTreeWidget(NavigationWidget): ...@@ -345,9 +388,9 @@ class NavigationTreeWidget(NavigationWidget):
def _onClicked(self, triggerByUser, clickArrow): def _onClicked(self, triggerByUser, clickArrow):
if not self.isCompacted: if not self.isCompacted:
if self.isSelectable and not self.isSelected and not clickArrow: if self.isSelectable and not self.isSelected and not clickArrow:
self.setExpanded(True) self.setExpanded(True, ani=True)
else: else:
self.setExpanded(not self.isExpanded) self.setExpanded(not self.isExpanded, ani=True)
if not clickArrow or self.isCompacted: if not clickArrow or self.isCompacted:
self.clicked.emit(triggerByUser) self.clicked.emit(triggerByUser)
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
from typing import Union from typing import Union
from PyQt5.QtCore import pyqtSignal, QUrl, Qt, QRectF, QSize, QPoint, pyqtProperty from PyQt5.QtCore import pyqtSignal, QUrl, Qt, QRectF, QSize, QPoint, pyqtProperty
from PyQt5.QtGui import QDesktopServices, QIcon, QPainter from PyQt5.QtGui import QDesktopServices, QIcon, QPainter, QFont
from PyQt5.QtWidgets import QHBoxLayout, QPushButton, QRadioButton, QToolButton, QApplication, QWidget, QSizePolicy from PyQt5.QtWidgets import QHBoxLayout, QPushButton, QRadioButton, QToolButton, QApplication, QWidget, QSizePolicy
from ...common.animation import TranslateYAnimation from ...common.animation import TranslateYAnimation
from ...common.icon import FluentIconBase, drawIcon, isDarkTheme, Theme, toQIcon from ...common.icon import FluentIconBase, drawIcon, isDarkTheme, Theme, toQIcon
from ...common.icon import FluentIcon as FIF from ...common.icon import FluentIcon as FIF
from ...common.font import setFont
from ...common.style_sheet import FluentStyleSheet from ...common.style_sheet import FluentStyleSheet
from ...common.overload import singledispatchmethod from ...common.overload import singledispatchmethod
from .menu import RoundMenu from .menu import RoundMenu
...@@ -24,6 +25,7 @@ class PushButton(QPushButton): ...@@ -24,6 +25,7 @@ class PushButton(QPushButton):
self.isHover = False self.isHover = False
self.setIconSize(QSize(16, 16)) self.setIconSize(QSize(16, 16))
self.setIcon(None) self.setIcon(None)
setFont(self)
self._postInit() self._postInit()
@__init__.register @__init__.register
...@@ -132,6 +134,7 @@ class HyperlinkButton(QPushButton): ...@@ -132,6 +134,7 @@ class HyperlinkButton(QPushButton):
self._url = QUrl() self._url = QUrl()
FluentStyleSheet.BUTTON.apply(self) FluentStyleSheet.BUTTON.apply(self)
self.setCursor(Qt.PointingHandCursor) self.setCursor(Qt.PointingHandCursor)
setFont(self)
self.clicked.connect(lambda i: QDesktopServices.openUrl(self.getUrl())) self.clicked.connect(lambda i: QDesktopServices.openUrl(self.getUrl()))
@__init__.register @__init__.register
...@@ -174,6 +177,7 @@ class ToolButton(QToolButton): ...@@ -174,6 +177,7 @@ class ToolButton(QToolButton):
self.isHover = False self.isHover = False
self.setIconSize(QSize(16, 16)) self.setIconSize(QSize(16, 16))
self.setIcon(QIcon()) self.setIcon(QIcon())
setFont(self)
self._postInit() self._postInit()
@__init__.register @__init__.register
......
...@@ -7,6 +7,7 @@ from PyQt5.QtWidgets import QHBoxLayout, QLineEdit, QToolButton, QTextEdit, QPla ...@@ -7,6 +7,7 @@ from PyQt5.QtWidgets import QHBoxLayout, QLineEdit, QToolButton, QTextEdit, QPla
from ...common.style_sheet import FluentStyleSheet, themeColor from ...common.style_sheet import FluentStyleSheet, themeColor
from ...common.icon import isDarkTheme, FluentIconBase, drawIcon from ...common.icon import isDarkTheme, FluentIconBase, drawIcon
from ...common.icon import FluentIcon as FIF from ...common.icon import FluentIcon as FIF
from ...common.font import setFont
from .menu import LineEditMenu, TextEditMenu from .menu import LineEditMenu, TextEditMenu
from .scroll_bar import SmoothScrollDelegate from .scroll_bar import SmoothScrollDelegate
...@@ -62,6 +63,7 @@ class LineEdit(QLineEdit): ...@@ -62,6 +63,7 @@ class LineEdit(QLineEdit):
FluentStyleSheet.LINE_EDIT.apply(self) FluentStyleSheet.LINE_EDIT.apply(self)
self.setFixedHeight(33) self.setFixedHeight(33)
self.setAttribute(Qt.WA_MacShowFocusRect, False) self.setAttribute(Qt.WA_MacShowFocusRect, False)
setFont(self)
self.hBoxLayout = QHBoxLayout(self) self.hBoxLayout = QHBoxLayout(self)
self.clearButton = LineEditButton(FIF.CLOSE, self) self.clearButton = LineEditButton(FIF.CLOSE, self)
...@@ -156,6 +158,7 @@ class TextEdit(QTextEdit): ...@@ -156,6 +158,7 @@ class TextEdit(QTextEdit):
super().__init__(parent=parent) super().__init__(parent=parent)
self.scrollDelegate = SmoothScrollDelegate(self) self.scrollDelegate = SmoothScrollDelegate(self)
FluentStyleSheet.LINE_EDIT.apply(self) FluentStyleSheet.LINE_EDIT.apply(self)
setFont(self)
def contextMenuEvent(self, e): def contextMenuEvent(self, e):
menu = TextEditMenu(self) menu = TextEditMenu(self)
...@@ -169,6 +172,7 @@ class PlainTextEdit(QPlainTextEdit): ...@@ -169,6 +172,7 @@ class PlainTextEdit(QPlainTextEdit):
super().__init__(parent=parent) super().__init__(parent=parent)
self.scrollDelegate = SmoothScrollDelegate(self) self.scrollDelegate = SmoothScrollDelegate(self)
FluentStyleSheet.LINE_EDIT.apply(self) FluentStyleSheet.LINE_EDIT.apply(self)
setFont(self)
def contextMenuEvent(self, e): def contextMenuEvent(self, e):
menu = TextEditMenu(self) menu = TextEditMenu(self)
......
...@@ -8,6 +8,7 @@ from PyQt5.QtWidgets import (QSpinBox, QDoubleSpinBox, QToolButton, QHBoxLayout, ...@@ -8,6 +8,7 @@ from PyQt5.QtWidgets import (QSpinBox, QDoubleSpinBox, QToolButton, QHBoxLayout,
from ...common.style_sheet import FluentStyleSheet, themeColor from ...common.style_sheet import FluentStyleSheet, themeColor
from ...common.icon import FluentIconBase, Theme, getIconColor from ...common.icon import FluentIconBase, Theme, getIconColor
from ...common.font import setFont
from ...components.widgets import LineEditMenu from ...components.widgets import LineEditMenu
...@@ -62,6 +63,7 @@ class Ui_SpinBox: ...@@ -62,6 +63,7 @@ class Ui_SpinBox:
FluentStyleSheet.SPIN_BOX.apply(self) FluentStyleSheet.SPIN_BOX.apply(self)
self.setButtonSymbols(QSpinBox.NoButtons) self.setButtonSymbols(QSpinBox.NoButtons)
self.setFixedHeight(33) self.setFixedHeight(33)
setFont(self)
self.hBoxLayout = QHBoxLayout(self) self.hBoxLayout = QHBoxLayout(self)
self.upButton = SpinButton(SpinIcon.UP, self) self.upButton = SpinButton(SpinIcon.UP, self)
......
...@@ -6,6 +6,7 @@ from PyQt5.QtGui import QPainter, QColor, QKeyEvent, QPalette ...@@ -6,6 +6,7 @@ from PyQt5.QtGui import QPainter, QColor, QKeyEvent, QPalette
from PyQt5.QtWidgets import (QStyledItemDelegate, QApplication, QStyleOptionViewItem, from PyQt5.QtWidgets import (QStyledItemDelegate, QApplication, QStyleOptionViewItem,
QTableView, QTableWidget, QWidget, QTableWidgetItem) QTableView, QTableWidget, QWidget, QTableWidgetItem)
from ...common.font import getFont
from ...common.style_sheet import isDarkTheme, FluentStyleSheet, themeColor from ...common.style_sheet import isDarkTheme, FluentStyleSheet, themeColor
from .line_edit import LineEdit from .line_edit import LineEdit
from .scroll_bar import SmoothScrollDelegate from .scroll_bar import SmoothScrollDelegate
...@@ -78,6 +79,7 @@ class TableItemDelegate(QStyledItemDelegate): ...@@ -78,6 +79,7 @@ class TableItemDelegate(QStyledItemDelegate):
def initStyleOption(self, option: QStyleOptionViewItem, index: QModelIndex): def initStyleOption(self, option: QStyleOptionViewItem, index: QModelIndex):
super().initStyleOption(option, index) super().initStyleOption(option, index)
option.font = getFont(13)
if isDarkTheme(): if isDarkTheme():
option.palette.setColor(QPalette.Text, Qt.white) option.palette.setColor(QPalette.Text, Qt.white)
option.palette.setColor(QPalette.HighlightedText, Qt.white) option.palette.setColor(QPalette.HighlightedText, Qt.white)
......
# coding:utf-8 # coding:utf-8
import typing
from PyQt5.QtCore import Qt, QSize from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QPainter, QColor from PyQt5.QtGui import QPainter, QColor, QPalette
from PyQt5.QtWidgets import QWidget, QTreeWidget, QStyledItemDelegate, QStyle, QTreeView from PyQt5.QtWidgets import QTreeWidget, QStyledItemDelegate, QStyle, QTreeView
from ...common.style_sheet import FluentStyleSheet, themeColor, isDarkTheme from ...common.style_sheet import FluentStyleSheet, themeColor, isDarkTheme
from ...common.font import getFont
from .scroll_area import SmoothScrollDelegate from .scroll_area import SmoothScrollDelegate
...@@ -39,6 +39,16 @@ class TreeItemDelegate(QStyledItemDelegate): ...@@ -39,6 +39,16 @@ class TreeItemDelegate(QStyledItemDelegate):
painter.restore() painter.restore()
def initStyleOption(self, option, index):
super().initStyleOption(option, index)
option.font = getFont(13)
if isDarkTheme():
option.palette.setColor(QPalette.Text, Qt.white)
option.palette.setColor(QPalette.HighlightedText, Qt.white)
else:
option.palette.setColor(QPalette.Text, Qt.black)
option.palette.setColor(QPalette.HighlightedText, Qt.black)
class TreeViewBase: class TreeViewBase:
""" Tree view base class """ """ Tree view base class """
......
...@@ -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.9.0", version="0.9.1",
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.
先完成此消息的编辑!
想要评论请 注册