This commit is contained in:
2025-10-10 17:16:08 +08:00
parent ed947743fc
commit 062b1e24e9
281 changed files with 536 additions and 109 deletions

View File

@@ -4,47 +4,34 @@ from PySide6.QtCore import QSize
from codes.common import clibs
from codes.common.signal_bus import signal_bus
from codes.common.qss_reloader import qss_reloader
class SToolBar(QToolBar):
def __init__(self, parent=None):
super().__init__(parent)
self.predos()
self.pre_do()
self.init_ui()
self.setup_slot()
self.post_do()
def predos(self):
def pre_do(self):
...
def init_ui(self):
self.setObjectName("SToolBar")
# switch
self.on_icon = QIcon(f"{clibs.base_path}/assets/media/switch_on.png") # 开状态图标
self.off_icon = QIcon(f"{clibs.base_path}/assets/media/switch_off.png") # 关状态图标
self.on_icon = QIcon(clibs.on_icon) # 开状态图标
self.off_icon = QIcon(clibs.off_icon) # 关状态图标
self.ac_switch = QAction(self.on_icon, "", self)
self.ac_switch.setMenuRole(QAction.MenuRole.NoRole)
self.ac_switch.setStatusTip("Switch side bar")
self.ac_switch.setToolTip("Ctrl+Alt+T")
self.ac_switch.setCheckable(True) # 二态
self.ac_switch.setCheckable(True)
self.ac_switch.setChecked(True)
self.ac_switch.setObjectName("acSwitch")
self.setIconSize(QSize(30, 30)) # ← 一行决定图标像素
self.setIconSize(QSize(30, 30))
self.addAction(self.ac_switch)
btn = self.widgetForAction(self.ac_switch) # 取出实际 QToolButton
btn.setStyleSheet("""
QToolButton {
background: transparent;
border: none;
outline: none;
}
/* 所有伪状态都透明,不让 Qt 画实心矩形 */
QToolButton::hover,
QToolButton::pressed,
QToolButton::checked {
background: transparent;
border: none;
outline: none;
}
""")
btn.setObjectName("ac_switch")
# homepage
self.ac_homepage = QAction()
@@ -78,6 +65,10 @@ class SToolBar(QToolBar):
self.ac_about.setText("关于")
self.addAction(self.ac_about)
def post_do(self):
qss_reloader.register(clibs.qss_toolbar, self)
self.setup_slot()
def setup_slot(self):
self.ac_switch.toggled.connect(self.ac_sw)
self.ac_homepage.triggered.connect(self.ac_hp)