From 6525507cef530fd0d2e439888db73fdfb2268d66 Mon Sep 17 00:00:00 2001 From: wuyuesong <1377030423@qq.com> Date: Sun, 27 Oct 2024 22:42:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=A0=B7=E5=BC=8F=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usr/share/aiassistant/mainwin.py | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/usr/share/aiassistant/mainwin.py b/usr/share/aiassistant/mainwin.py index bd634096..ea30d045 100644 --- a/usr/share/aiassistant/mainwin.py +++ b/usr/share/aiassistant/mainwin.py @@ -675,3 +675,56 @@ class Mainwin(QWidget): # widget.show() # app.exec_() + +class SettingMenu(QMenu): + def __init__(self, *args, **kwargs): + super(SettingMenu, self).__init__() + self.radius = 5 + self.setStyleSheet( + ''' + QMenu {{ + /* 半透明效果 */ + border-radius: {radius}; + border: 2px solid rgb(255, 255, 255); + background-color: rgba(255, 255, 255, 230); + }} + + QMenu::item {{ + border-radius: {radius}; + /* 这个距离很麻烦需要根据菜单的长度和图标等因素微调 */ + padding: 8px 48px 8px 12px; /* 36px是文字距离左侧距离*/ + background-color: transparent; + }} + + /* 鼠标悬停和按下效果 */ + QMenu::item:selected {{ + border-radius: {radius}; + /* 半透明效果 */ + background-color: rgba(230, 240, 255, 232); + }} + + /* 禁用效果 */ + QMenu::item:disabled {{ + border-radius: {radius}; + background-color: transparent; + }} + + /* 图标距离左侧距离 */ + QMenu::icon {{ + left: 15px; + }} + + /* 分割线效果 */ + QMenu::separator {{ + height: 1px; + background-color: rgb(232, 236, 243); + }} + '''.format(radius=self.radius)) + + def resizeEvent(self, event): + # 添加蒙版 + path = QPainterPath() + path.addRoundedRect(QRectF(self.rect()), self.radius, self.radius) + region = QRegion(path.toFillPolygon(QTransform()).toPolygon()) + self.setMask(region) + -- Gitee