Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
k54kdk
PyQt Fluent Widgets
提交
0c3d3f6d
P
PyQt Fluent Widgets
项目概览
k54kdk
/
PyQt Fluent Widgets
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PyQt Fluent Widgets
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
0c3d3f6d
编写于
8月 11, 2023
作者:
之一Yo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加自定义菜单组件的功能
上级
bcf509b5
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
253222 addition
and
252973 deletion
+253222
-252973
examples/gallery/app/common/resource.py
examples/gallery/app/common/resource.py
+252831
-252807
examples/gallery/app/resource/i18n/gallery.zh_CN.qm
examples/gallery/app/resource/i18n/gallery.zh_CN.qm
+0
-0
examples/gallery/app/resource/i18n/gallery.zh_CN.ts
examples/gallery/app/resource/i18n/gallery.zh_CN.ts
+106
-81
examples/gallery/app/resource/i18n/gallery.zh_HK.ts
examples/gallery/app/resource/i18n/gallery.zh_HK.ts
+106
-81
examples/gallery/app/view/menu_interface.py
examples/gallery/app/view/menu_interface.py
+58
-2
examples/widget_menu/demo.py
examples/widget_menu/demo.py
+84
-0
examples/widget_menu/resource/shoko.png
examples/widget_menu/resource/shoko.png
+0
-0
qfluentwidgets/components/widgets/menu.py
qfluentwidgets/components/widgets/menu.py
+37
-2
未找到文件。
examples/gallery/app/common/resource.py
浏览文件 @
0c3d3f6d
此差异已折叠。
点击以展开。
examples/gallery/app/resource/i18n/gallery.zh_CN.qm
浏览文件 @
0c3d3f6d
无法预览此类型文件
examples/gallery/app/resource/i18n/gallery.zh_CN.ts
浏览文件 @
0c3d3f6d
此差异已折叠。
点击以展开。
examples/gallery/app/resource/i18n/gallery.zh_HK.ts
浏览文件 @
0c3d3f6d
此差异已折叠。
点击以展开。
examples/gallery/app/view/menu_interface.py
浏览文件 @
0c3d3f6d
# coding:utf-8
# coding:utf-8
from
PyQt5.QtCore
import
QPoint
,
Qt
,
QStandardPaths
from
PyQt5.QtCore
import
QPoint
,
Qt
,
QStandardPaths
from
PyQt5.QtGui
import
QColor
from
PyQt5.QtWidgets
import
QAction
,
QWidget
,
QLabel
,
QVBoxLayout
,
QFileDialog
,
QActionGroup
from
PyQt5.QtWidgets
import
QAction
,
QWidget
,
QLabel
,
QVBoxLayout
,
QFileDialog
,
QActionGroup
from
qfluentwidgets
import
(
RoundMenu
,
PushButton
,
Action
,
CommandBar
,
Action
,
TransparentDropDownPushButton
,
from
qfluentwidgets
import
(
RoundMenu
,
PushButton
,
Action
,
CommandBar
,
Action
,
TransparentDropDownPushButton
,
setFont
,
CommandBarView
,
Flyout
,
ImageLabel
,
FlyoutAnimationType
,
CheckableMenu
,
setFont
,
CommandBarView
,
Flyout
,
ImageLabel
,
FlyoutAnimationType
,
CheckableMenu
,
MenuIndicatorType
)
MenuIndicatorType
,
AvatarWidget
,
isDarkTheme
,
BodyLabel
,
CaptionLabel
,
HyperlinkButton
)
from
qfluentwidgets
import
FluentIcon
as
FIF
from
qfluentwidgets
import
FluentIcon
as
FIF
from
.gallery_interface
import
GalleryInterface
from
.gallery_interface
import
GalleryInterface
...
@@ -53,6 +54,18 @@ class MenuInterface(GalleryInterface):
...
@@ -53,6 +54,18 @@ class MenuInterface(GalleryInterface):
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/menu/demo.py'
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/menu/demo.py'
)
)
# custom widget menu
self
.
button3
=
PushButton
(
self
.
tr
(
'Show menu'
))
self
.
button3
.
clicked
.
connect
(
lambda
:
self
.
createCustomWidgetMenu
(
self
.
button3
.
mapToGlobal
(
QPoint
(
self
.
button3
.
width
()
+
5
,
-
100
))))
self
.
addExampleCard
(
self
.
tr
(
'Rounded corners menu with custom widget'
),
self
.
button3
,
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/widget_menu/demo.py'
)
# checkable menu
# checkable menu
self
.
button2
=
PushButton
(
self
.
tr
(
'Show menu'
))
self
.
button2
=
PushButton
(
self
.
tr
(
'Show menu'
))
self
.
button2
.
clicked
.
connect
(
lambda
:
self
.
createCheckableMenu
(
self
.
button2
.
clicked
.
connect
(
lambda
:
self
.
createCheckableMenu
(
...
@@ -133,6 +146,23 @@ class MenuInterface(GalleryInterface):
...
@@ -133,6 +146,23 @@ class MenuInterface(GalleryInterface):
menu
.
exec
(
pos
,
ani
=
True
)
menu
.
exec
(
pos
,
ani
=
True
)
def
createCustomWidgetMenu
(
self
,
pos
):
menu
=
RoundMenu
(
parent
=
self
)
# add custom widget
card
=
ProfileCard
(
':/gallery/images/shoko.png'
,
self
.
tr
(
'Shoko'
),
'shokokawaii@outlook.com'
,
menu
)
menu
.
addWidget
(
card
,
selectable
=
False
)
menu
.
addSeparator
()
menu
.
addActions
([
Action
(
FIF
.
PEOPLE
,
self
.
tr
(
'Manage account profile'
)),
Action
(
FIF
.
SHOPPING_CART
,
self
.
tr
(
'Payment method'
)),
Action
(
FIF
.
CODE
,
self
.
tr
(
'Redemption code and gift card'
)),
])
menu
.
addSeparator
()
menu
.
addAction
(
Action
(
FIF
.
SETTING
,
self
.
tr
(
'Settings'
)))
menu
.
exec
(
pos
)
def
createCheckableMenu
(
self
,
pos
=
None
):
def
createCheckableMenu
(
self
,
pos
=
None
):
menu
=
CheckableMenu
(
parent
=
self
,
indicatorType
=
MenuIndicatorType
.
RADIO
)
menu
=
CheckableMenu
(
parent
=
self
,
indicatorType
=
MenuIndicatorType
.
RADIO
)
...
@@ -203,4 +233,30 @@ class MenuInterface(GalleryInterface):
...
@@ -203,4 +233,30 @@ class MenuInterface(GalleryInterface):
if
not
ok
:
if
not
ok
:
return
return
self
.
imageLabel
.
image
.
save
(
path
)
self
.
imageLabel
.
image
.
save
(
path
)
\ No newline at end of file
class
ProfileCard
(
QWidget
):
""" Profile card """
def
__init__
(
self
,
avatarPath
:
str
,
name
:
str
,
email
:
str
,
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
self
.
avatar
=
AvatarWidget
(
avatarPath
,
self
)
self
.
nameLabel
=
BodyLabel
(
name
,
self
)
self
.
emailLabel
=
CaptionLabel
(
email
,
self
)
self
.
logoutButton
=
HyperlinkButton
(
'https://github.com/zhiyiYo/QMaterialWidgets'
,
'注销'
,
self
)
color
=
QColor
(
206
,
206
,
206
)
if
isDarkTheme
()
else
QColor
(
96
,
96
,
96
)
self
.
emailLabel
.
setStyleSheet
(
'QLabel{color: '
+
color
.
name
()
+
'}'
)
color
=
QColor
(
255
,
255
,
255
)
if
isDarkTheme
()
else
QColor
(
0
,
0
,
0
)
self
.
nameLabel
.
setStyleSheet
(
'QLabel{color: '
+
color
.
name
()
+
'}'
)
setFont
(
self
.
logoutButton
,
13
)
self
.
setFixedSize
(
307
,
82
)
self
.
avatar
.
setRadius
(
24
)
self
.
avatar
.
move
(
2
,
6
)
self
.
nameLabel
.
move
(
64
,
13
)
self
.
emailLabel
.
move
(
64
,
32
)
self
.
logoutButton
.
move
(
52
,
48
)
examples/widget_menu/demo.py
0 → 100644
浏览文件 @
0c3d3f6d
# coding:utf-8
import
sys
from
PyQt5
import
QtGui
from
PyQt5.QtCore
import
Qt
from
PyQt5.QtGui
import
QIcon
,
QColor
from
PyQt5.QtWidgets
import
QApplication
,
QWidget
,
QLabel
,
QHBoxLayout
from
qfluentwidgets
import
(
RoundMenu
,
FluentIcon
,
Action
,
AvatarWidget
,
BodyLabel
,
HyperlinkButton
,
CaptionLabel
,
setFont
,
setTheme
,
Theme
,
isDarkTheme
)
class
ProfileCard
(
QWidget
):
""" Profile card """
def
__init__
(
self
,
avatarPath
:
str
,
name
:
str
,
email
:
str
,
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
self
.
avatar
=
AvatarWidget
(
avatarPath
,
self
)
self
.
nameLabel
=
BodyLabel
(
name
,
self
)
self
.
emailLabel
=
CaptionLabel
(
email
,
self
)
self
.
logoutButton
=
HyperlinkButton
(
'https://github.com/zhiyiYo/QMaterialWidgets'
,
'注销'
,
self
)
color
=
QColor
(
206
,
206
,
206
)
if
isDarkTheme
()
else
QColor
(
96
,
96
,
96
)
self
.
emailLabel
.
setStyleSheet
(
'QLabel{color: '
+
color
.
name
()
+
'}'
)
color
=
QColor
(
255
,
255
,
255
)
if
isDarkTheme
()
else
QColor
(
0
,
0
,
0
)
self
.
nameLabel
.
setStyleSheet
(
'QLabel{color: '
+
color
.
name
()
+
'}'
)
setFont
(
self
.
logoutButton
,
13
)
self
.
setFixedSize
(
307
,
82
)
self
.
avatar
.
setRadius
(
24
)
self
.
avatar
.
move
(
2
,
6
)
self
.
nameLabel
.
move
(
64
,
13
)
self
.
emailLabel
.
move
(
64
,
32
)
self
.
logoutButton
.
move
(
52
,
48
)
class
Demo
(
QWidget
):
def
__init__
(
self
):
super
().
__init__
()
# setTheme(Theme.DARK)
# self.setStyleSheet('Demo{background: rgb(32, 32, 32)}')
self
.
setStyleSheet
(
'Demo{background: white}'
)
self
.
setLayout
(
QHBoxLayout
())
self
.
label
=
BodyLabel
(
'Right-click your mouse'
,
self
)
self
.
label
.
setAlignment
(
Qt
.
AlignCenter
)
setFont
(
self
.
label
,
18
)
self
.
layout
().
addWidget
(
self
.
label
)
self
.
resize
(
400
,
400
)
def
contextMenuEvent
(
self
,
e
)
->
None
:
menu
=
RoundMenu
(
parent
=
self
)
# add custom widget
card
=
ProfileCard
(
'resource/shoko.png'
,
'硝子酱'
,
'shokokawaii@outlook.com'
,
menu
)
menu
.
addWidget
(
card
,
selectable
=
False
)
# menu.addWidget(card, selectable=True, onClick=lambda: print('666'))
menu
.
addSeparator
()
menu
.
addActions
([
Action
(
FluentIcon
.
PEOPLE
,
'管理账户和设置'
),
Action
(
FluentIcon
.
SHOPPING_CART
,
'支付方式'
),
Action
(
FluentIcon
.
CODE
,
'兑换代码和礼品卡'
),
])
menu
.
addSeparator
()
menu
.
addAction
(
Action
(
FluentIcon
.
SETTING
,
'设置'
))
menu
.
exec
(
e
.
globalPos
())
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
()
app
.
exec_
()
examples/widget_menu/resource/shoko.png
0 → 100644
浏览文件 @
0c3d3f6d
261.8 KB
qfluentwidgets/components/widgets/menu.py
浏览文件 @
0c3d3f6d
...
@@ -228,7 +228,8 @@ class MenuActionListWidget(QListWidget):
...
@@ -228,7 +228,8 @@ class MenuActionListWidget(QListWidget):
for
i
in
range
(
self
.
count
()):
for
i
in
range
(
self
.
count
()):
item
=
self
.
item
(
i
)
item
=
self
.
item
(
i
)
item
.
setSizeHint
(
item
.
sizeHint
().
width
(),
height
)
if
not
self
.
itemWidget
(
item
):
item
.
setSizeHint
(
item
.
sizeHint
().
width
(),
height
)
self
.
_itemHeight
=
height
self
.
_itemHeight
=
height
self
.
adjustSize
()
self
.
adjustSize
()
...
@@ -356,6 +357,37 @@ class RoundMenu(QMenu):
...
@@ -356,6 +357,37 @@ class RoundMenu(QMenu):
self
.
view
.
addItem
(
item
)
self
.
view
.
addItem
(
item
)
self
.
adjustSize
()
self
.
adjustSize
()
def
addWidget
(
self
,
widget
:
QWidget
,
selectable
=
True
,
onClick
=
None
):
""" add custom widget
Parameters
----------
widget: QWidget
custom widget
selectable: bool
whether the menu item is selectable
onClick: callable
the slot connected to item clicked signal
"""
action
=
QAction
()
action
.
setProperty
(
'selectable'
,
selectable
)
item
=
self
.
_createActionItem
(
action
)
item
.
setSizeHint
(
widget
.
size
())
self
.
view
.
addItem
(
item
)
self
.
view
.
setItemWidget
(
item
,
widget
)
if
not
selectable
:
item
.
setFlags
(
Qt
.
NoItemFlags
)
if
onClick
:
action
.
triggered
.
connect
(
onClick
)
self
.
adjustSize
()
def
_createActionItem
(
self
,
action
:
QAction
,
before
=
None
):
def
_createActionItem
(
self
,
action
:
QAction
,
before
=
None
):
""" create menu action item """
""" create menu action item """
if
not
before
:
if
not
before
:
...
@@ -560,10 +592,13 @@ class RoundMenu(QMenu):
...
@@ -560,10 +592,13 @@ class RoundMenu(QMenu):
self
.
adjustSize
()
self
.
adjustSize
()
def
_onItemClicked
(
self
,
item
):
def
_onItemClicked
(
self
,
item
):
action
=
item
.
data
(
Qt
.
UserRole
)
action
=
item
.
data
(
Qt
.
UserRole
)
# type: QAction
if
action
not
in
self
.
_actions
or
not
action
.
isEnabled
():
if
action
not
in
self
.
_actions
or
not
action
.
isEnabled
():
return
return
if
self
.
view
.
itemWidget
(
item
)
and
not
action
.
property
(
'selectable'
):
return
self
.
_hideMenu
(
False
)
self
.
_hideMenu
(
False
)
if
not
self
.
isSubMenu
:
if
not
self
.
isSubMenu
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录