Files
hk4e-gm-clone/ui2/theme.py
T

201 lines
6.1 KiB
Python

"""PySide6 深色 Material 主题 —— 对齐 hk4e-GM v2.0.1 的配色与控件质感。"""
from __future__ import annotations
import os
from PySide6.QtGui import QFont
from PySide6.QtWidgets import QApplication
BASE = os.path.dirname(os.path.abspath(__file__))
SKINS = os.path.join(BASE, "skins").replace("\\", "/")
BG = "#2D2D2D"
CARD = "#393939"
CARD_BORDER = "#464646"
SIDEBAR = "#202020"
SIDEBAR_HOVER = "#282828"
SIDEBAR_ACTIVE = "#252525"
TEXT = "#EEEEEE"
DIM = "#A6A6A6"
FAINT = "#7A7A7A"
BTN = "#556A7F"
ACCENT = "#80B9EE"
PRIMARY = "#FBC2EB"
PRIMARY_BG = "#614B56"
FIELD_LINE = "#8A8A8A"
FONT = "Microsoft YaHei UI"
QSS = f"""
* {{
font-family: "{FONT}";
color: {TEXT};
outline: none;
}}
QLabel, QPushButton, QLineEdit, QComboBox, QCheckBox, QListWidget, QTableWidget {{
font-size: 14px;
}}
QMainWindow, QWidget#Root {{ background: {BG}; }}
QWidget#Page {{ background: transparent; }}
QWidget#Sidebar {{ background: {SIDEBAR}; }}
QFrame#Card {{
background: {CARD};
border: 1px solid {CARD_BORDER};
border-radius: 8px;
}}
/* ---------- 输入:Material 下划线 ---------- */
QLineEdit {{
background: transparent;
border: none;
border-bottom: 1px solid {FIELD_LINE};
padding: 1px 0 3px 0;
selection-background-color: {BTN};
}}
QLineEdit:focus {{ border-bottom: 1px solid {ACCENT}; }}
QLineEdit:disabled {{ color: {FAINT}; }}
QComboBox {{
background: transparent;
border: none;
border-bottom: 1px solid {FIELD_LINE};
padding: 1px 20px 3px 0;
}}
QComboBox:focus {{ border-bottom: 1px solid {ACCENT}; }}
QComboBox::drop-down {{ border: none; width: 20px; }}
QComboBox::down-arrow {{ image: url({SKINS}/arrow.png); width: 10px; height: 6px; }}
QComboBox QAbstractItemView {{
background: #3E3E3E;
border: 1px solid #5A5A5A;
border-radius: 4px;
padding: 4px;
selection-background-color: {BTN};
}}
/* ---------- 按钮:药丸 ---------- */
QPushButton {{
background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 #5F7589, stop:0.5 {BTN}, stop:1 #4E6377);
border: 1px solid rgba(255,255,255,0.20);
border-radius: 16px;
padding: 0 14px;
color: #E9EDF2;
font-weight: 400;
}}
QPushButton:hover {{
background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 #6C8398, stop:1 #5B7186);
border: 1px solid rgba(255,255,255,0.32);
}}
QPushButton:pressed {{ background: #4A5F73; }}
QPushButton:disabled {{
background: rgba(85,106,127,0.30);
border: 1px solid rgba(255,255,255,0.08);
color: rgba(233,237,242,0.35);
}}
QPushButton#Small {{ padding: 0 10px; border-radius: 16px; }}
QPushButton#Primary {{
background: #614B56;
border: 1px solid rgba(251,194,235,0.60);
color: #FFFFFF;
}}
QPushButton#Primary:hover {{ background: #705764; }}
QPushButton#DangerBlue {{
background: #4D6277;
border: 1px solid rgba(255,255,255,0.18);
}}
QPushButton#DangerRed {{
background: #6F4754;
border: 1px solid rgba(251,194,235,0.38);
}}
QPushButton#Chip {{
background: transparent;
border: 1px solid rgba(255,255,255,0.42);
border-radius: 20px;
padding: 0 12px;
color: {TEXT};
}}
QPushButton#Chip:hover {{ background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.6); }}
QPushButton#Chip:checked {{
background: {PRIMARY_BG};
border: 1px solid {PRIMARY};
color: #FFFFFF;
}}
QPushButton#Flat {{ background: transparent; border: none; padding: 0; }}
QPushButton#Flat:hover {{ background: rgba(255,255,255,0.06); border-radius: 12px; }}
/* ---------- 文本 ---------- */
QLabel {{ background: transparent; }}
QLabel#Dim {{ color: {DIM}; }}
QLabel#Title {{ font-size: 20px; font-weight: bold; }}
QLabel#H2 {{ font-size: 15px; font-weight: bold; }}
QListWidget {{ background: transparent; border: none; }}
QListWidget::item {{ padding: 7px 6px; border-radius: 4px; }}
QListWidget::item:hover {{ background: rgba(255,255,255,0.05); }}
QListWidget::item:selected {{ background: {BTN}; color: #FFFFFF; }}
QTableWidget {{ background: transparent; border: none; gridline-color: #4F4F4F; }}
QHeaderView::section {{
background: transparent; color: {DIM}; border: none;
border-bottom: 1px solid #5A5A5A; padding: 7px 6px;
}}
QTableWidget::item:selected {{ background: {BTN}; }}
/* ---------- 滑块 ---------- */
QSlider::groove:horizontal {{ height: 2px; background: #6E6E6E; border-radius: 1px; }}
QSlider::sub-page:horizontal {{ height: 2px; background: {ACCENT}; border-radius: 1px; }}
QSlider::handle:horizontal {{
width: 12px; height: 12px; margin: -6px 0;
border-radius: 7px; background: #2D2D2D; border: 2px solid {PRIMARY};
}}
QSlider::handle:horizontal:hover {{ background: {PRIMARY_BG}; }}
/* ---------- 复选框 ---------- */
QCheckBox {{ spacing: 8px; }}
QCheckBox::indicator {{
width: 16px; height: 16px;
border: 1px solid #9A9A9A; border-radius: 2px;
background: transparent;
}}
QCheckBox::indicator:hover {{ border-color: {ACCENT}; }}
QCheckBox::indicator:checked {{
background: {BTN}; border: 1px solid {BTN};
image: url({SKINS}/check.png);
}}
/* ---------- 日志 / 滚动条 ---------- */
QTextEdit, QPlainTextEdit {{
background: {CARD};
border: 1px solid {CARD_BORDER};
border-radius: 8px;
color: {TEXT};
padding: 6px;
selection-background-color: {BTN};
}}
QScrollBar:vertical {{ background: transparent; width: 8px; margin: 2px; }}
QScrollBar::handle:vertical {{ background: #5A5A5A; border-radius: 4px; min-height: 24px; }}
QScrollBar::handle:vertical:hover {{ background: #6E6E6E; }}
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {{ height: 0; }}
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {{ background: transparent; }}
QScrollBar:horizontal {{ background: transparent; height: 8px; margin: 2px; }}
QScrollBar::handle:horizontal {{ background: #5A5A5A; border-radius: 4px; min-width: 24px; }}
QToolTip {{
background: #3E3E3E; color: {TEXT};
border: 1px solid #5A5A5A; border-radius: 4px; padding: 4px 6px;
}}
"""
def app_font(size: int = 14) -> QFont:
f = QFont(FONT)
f.setPixelSize(size)
return f
def install(app: QApplication) -> None:
app.setStyle("Fusion")
app.setFont(app_font(14))
app.setStyleSheet(QSS)