-
-
Notifications
You must be signed in to change notification settings - Fork 709
feat(navigation): add NavigationUserCard component #1085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d7283b0
feat(navigation): add NavigationUserCard component
JustKanade 7c6823a
fix(NavigationUserCard): correct title color by using alpha instead o…
JustKanade 90a48c3
refactor(Navigation): refactor NavigationUserCard to inherit from Nav…
JustKanade f919076
refactor(NavigationUserCard): remove click behavior customization fea…
JustKanade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # coding:utf-8 | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| #sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent)) | ||
|
|
||
| from PyQt5.QtCore import Qt | ||
| from PyQt5.QtGui import QIcon | ||
| from PyQt5.QtWidgets import QApplication, QFrame, QHBoxLayout | ||
| from qfluentwidgets import (NavigationItemPosition, MessageBox, FluentWindow, SubtitleLabel, setFont, | ||
| NavigationUserCardClickBehavior) | ||
| from qfluentwidgets import FluentIcon as FIF | ||
|
|
||
|
|
||
| class Widget(QFrame): | ||
|
|
||
| def __init__(self, text: str, parent=None): | ||
| super().__init__(parent=parent) | ||
| self.label = SubtitleLabel(text, self) | ||
| self.hBoxLayout = QHBoxLayout(self) | ||
|
|
||
| setFont(self.label, 24) | ||
| self.label.setAlignment(Qt.AlignCenter) | ||
| self.hBoxLayout.addWidget(self.label, 1, Qt.AlignCenter) | ||
| self.setObjectName(text.replace(' ', '-')) | ||
|
|
||
|
|
||
| class Window(FluentWindow): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
| # create sub interface | ||
| self.homeInterface = Widget('Home Interface', self) | ||
| self.musicInterface = Widget('Music Interface', self) | ||
| self.videoInterface = Widget('Video Interface', self) | ||
| self.settingInterface = Widget('Setting Interface', self) | ||
|
|
||
| self.initNavigation() | ||
| self.initWindow() | ||
|
|
||
| def initNavigation(self): | ||
| # add user card with custom parameters | ||
| self.userCard = self.navigationInterface.addUserCard( | ||
| routeKey='userCard', | ||
| avatar='resource/shoko.png', | ||
| title='zhiyiYo', | ||
| subtitle='shokokawaii@outlook.com', | ||
| onClick=self.showMessageBox, | ||
| position=NavigationItemPosition.TOP, | ||
| aboveMenuButton=False # place below the expand/collapse button | ||
| ) | ||
|
|
||
| # customize user card (optional) | ||
| # self.userCard.setTitleFontSize(15) | ||
| # self.userCard.setSubtitleFontSize(11) | ||
| # self.userCard.setAnimationDuration(300) | ||
|
|
||
| # placement: set aboveMenuButton=True to place card above expand/collapse button | ||
| # default: aboveMenuButton=False (card placed below menu button) | ||
|
|
||
| # customize click behavior in compact mode (optional) | ||
| # NavigationUserCardClickBehavior.EXPAND: expand navigation panel (default) | ||
| # NavigationUserCardClickBehavior.CALLBACK: trigger onClick callback | ||
| # NavigationUserCardClickBehavior.EXPAND_AND_CALLBACK: both expand and callback | ||
| # self.userCard.setCompactClickBehavior(NavigationUserCardClickBehavior.EXPAND_AND_CALLBACK) | ||
|
|
||
| # add navigation items | ||
| self.addSubInterface(self.homeInterface, FIF.HOME, 'Home') | ||
| self.addSubInterface(self.musicInterface, FIF.MUSIC, 'Music library') | ||
|
|
||
| self.navigationInterface.addSeparator() | ||
|
|
||
| self.addSubInterface(self.videoInterface, FIF.VIDEO, 'Video library') | ||
| self.addSubInterface(self.settingInterface, FIF.SETTING, 'Settings', NavigationItemPosition.BOTTOM) | ||
|
|
||
| def initWindow(self): | ||
| self.resize(900, 700) | ||
| self.setWindowIcon(QIcon('resource/logo.png')) | ||
| self.setWindowTitle('Navigation User Card') | ||
|
|
||
| desktop = QApplication.desktop().availableGeometry() | ||
| w, h = desktop.width(), desktop.height() | ||
| self.move(w//2 - self.width()//2, h//2 - self.height()//2) | ||
|
|
||
| def showMessageBox(self): | ||
| w = MessageBox( | ||
| 'User Card', | ||
| 'This is a navigation user card that displays avatar, title and subtitle.\n\n' | ||
| 'Placement:\n' | ||
| '• aboveMenuButton=True: Place above expand/collapse button\n' | ||
| '• aboveMenuButton=False: Place below menu button (default)\n\n' | ||
| 'Click behavior:\n' | ||
| '• EXPAND: Expand navigation panel in compact mode (default)\n' | ||
| '• CALLBACK: Trigger onClick callback in both modes\n' | ||
| '• EXPAND_AND_CALLBACK: Both expand and trigger callback', | ||
| self | ||
| ) | ||
| w.exec_() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) | ||
| QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) | ||
| QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) | ||
|
|
||
| app = QApplication(sys.argv) | ||
| w = Window() | ||
| w.show() | ||
| app.exec_() |
50 changes: 50 additions & 0 deletions
50
examples/navigation/navigation_user_card/resource/dark/demo.qss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| Widget > QLabel { | ||
| font: 24px 'Segoe UI', 'Microsoft YaHei'; | ||
| } | ||
|
|
||
| Widget { | ||
| border: 1px solid rgb(29, 29, 29); | ||
| border-right: none; | ||
| border-bottom: none; | ||
| border-top-left-radius: 10px; | ||
| background-color: rgb(39, 39, 39); | ||
| } | ||
|
|
||
| Window { | ||
| background-color: rgb(32, 32, 32); | ||
| } | ||
|
|
||
| StandardTitleBar { | ||
| background-color: rgb(32, 32, 32); | ||
| } | ||
|
|
||
| StandardTitleBar > QLabel, | ||
| Widget > QLabel { | ||
| color: white; | ||
| } | ||
|
|
||
|
|
||
| MinimizeButton { | ||
| qproperty-normalColor: white; | ||
| qproperty-normalBackgroundColor: transparent; | ||
| qproperty-hoverColor: white; | ||
| qproperty-hoverBackgroundColor: rgba(255, 255, 255, 26); | ||
| qproperty-pressedColor: white; | ||
| qproperty-pressedBackgroundColor: rgba(255, 255, 255, 51) | ||
| } | ||
|
|
||
|
|
||
| MaximizeButton { | ||
| qproperty-normalColor: white; | ||
| qproperty-normalBackgroundColor: transparent; | ||
| qproperty-hoverColor: white; | ||
| qproperty-hoverBackgroundColor: rgba(255, 255, 255, 26); | ||
| qproperty-pressedColor: white; | ||
| qproperty-pressedBackgroundColor: rgba(255, 255, 255, 51) | ||
| } | ||
|
|
||
| CloseButton { | ||
| qproperty-normalColor: white; | ||
| qproperty-normalBackgroundColor: transparent; | ||
| } | ||
|
|
16 changes: 16 additions & 0 deletions
16
examples/navigation/navigation_user_card/resource/light/demo.qss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| Widget > QLabel { | ||
| font: 24px 'Segoe UI', 'Microsoft YaHei'; | ||
| } | ||
|
|
||
| Widget { | ||
| border: 1px solid rgb(229, 229, 229); | ||
| border-right: none; | ||
| border-bottom: none; | ||
| border-top-left-radius: 10px; | ||
| background-color: rgb(249, 249, 249); | ||
| } | ||
|
|
||
| Window { | ||
| background-color: rgb(243, 243, 243); | ||
| } | ||
|
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.