日历黑白模式适配

Maziang 3 months ago
parent 9588630f51
commit 2cdf760dd1

@ -13,6 +13,9 @@ from PyQt5.QtWidgets import (
from PyQt5.QtCore import QDate, Qt, pyqtSignal
from PyQt5.QtGui import QFont
# 导入主题管理器
from .theme_manager import theme_manager
class CalendarWidget(QWidget):
"""日历组件类"""
@ -24,6 +27,7 @@ class CalendarWidget(QWidget):
super().__init__(parent)
self.setup_ui()
self.setup_connections()
self.setup_theme()
def setup_ui(self):
"""设置UI界面"""
@ -266,6 +270,295 @@ class CalendarWidget(QWidget):
date = QDate.fromString(date, "yyyy-MM-dd")
self.calendar.setSelectedDate(date)
self.update_date_label(date)
def setup_theme(self):
"""设置主题"""
# 连接主题切换信号
theme_manager.theme_changed.connect(self.on_theme_changed)
# 应用当前主题
self.apply_theme()
def apply_theme(self):
"""应用主题样式"""
is_dark = theme_manager.is_dark_theme()
if is_dark:
# 深色主题样式
self.setStyleSheet("""
QWidget {
background-color: #2c2c2e;
color: #f0f0f0;
}
""")
# 更新日历控件样式
self.calendar.setStyleSheet("""
QCalendarWidget {
background-color: #2c2c2e;
border: 1px solid #404040;
border-radius: 4px;
}
QCalendarWidget QToolButton {
height: 30px;
width: 80px;
color: #f0f0f0;
font-size: 12px;
font-weight: bold;
background-color: #3a3a3c;
border: 1px solid #4a4a4c;
border-radius: 4px;
}
QCalendarWidget QToolButton:hover {
background-color: #4a4a4c;
}
QCalendarWidget QMenu {
width: 150px;
left: 20px;
color: #f0f0f0;
font-size: 12px;
background-color: #3a3a3c;
border: 1px solid #4a4a4c;
}
QCalendarWidget QSpinBox {
width: 80px;
font-size: 12px;
background-color: #3a3a3c;
selection-background-color: #0a84ff;
selection-color: #ffffff;
border: 1px solid #4a4a4c;
border-radius: 4px;
color: #f0f0f0;
}
QCalendarWidget QSpinBox::up-button {
subcontrol-origin: border;
subcontrol-position: top right;
width: 20px;
}
QCalendarWidget QSpinBox::down-button {
subcontrol-origin: border;
subcontrol-position: bottom right;
width: 20px;
}
QCalendarWidget QSpinBox::up-arrow {
width: 10px;
height: 10px;
}
QCalendarWidget QSpinBox::down-arrow {
width: 10px;
height: 10px;
}
QCalendarWidget QWidget {
alternate-background-color: #3a3a3c;
}
QCalendarWidget QAbstractItemView:enabled {
font-size: 12px;
selection-background-color: #0a84ff;
selection-color: #ffffff;
background-color: #2c2c2e;
color: #f0f0f0;
}
QCalendarWidget QWidget#qt_calendar_navigationbar {
background-color: #3a3a3c;
}
""")
# 更新标签样式
self.date_label.setStyleSheet("QLabel { color: #a0a0a0; }")
# 更新按钮样式
self.close_btn.setStyleSheet("""
QPushButton {
background-color: #3a3a3c;
border: 1px solid #4a4a4c;
border-radius: 12px;
font-size: 16px;
font-weight: bold;
color: #f0f0f0;
}
QPushButton:hover {
background-color: #4a4a4c;
}
""")
self.today_btn.setStyleSheet("""
QPushButton {
background-color: #0a84ff;
color: white;
border: none;
border-radius: 4px;
padding: 5px 10px;
}
QPushButton:hover {
background-color: #0066cc;
}
""")
self.clear_btn.setStyleSheet("""
QPushButton {
background-color: #3a3a3c;
color: #f0f0f0;
border: 1px solid #4a4a4c;
border-radius: 4px;
padding: 5px 10px;
}
QPushButton:hover {
background-color: #4a4a4c;
}
""")
self.insert_btn.setStyleSheet("""
QPushButton {
background-color: #32d74b;
color: #000000;
border: none;
border-radius: 4px;
padding: 5px 10px;
}
QPushButton:hover {
background-color: #24b334;
}
""")
else:
# 浅色主题样式
self.setStyleSheet("""
QWidget {
background-color: white;
color: #333333;
}
""")
# 更新日历控件样式
self.calendar.setStyleSheet("""
QCalendarWidget {
background-color: white;
border: 1px solid #ccc;
border-radius: 4px;
}
QCalendarWidget QToolButton {
height: 30px;
width: 80px;
color: #333;
font-size: 12px;
font-weight: bold;
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 4px;
}
QCalendarWidget QToolButton:hover {
background-color: #e0e0e0;
}
QCalendarWidget QMenu {
width: 150px;
left: 20px;
color: #333;
font-size: 12px;
background-color: white;
border: 1px solid #ccc;
}
QCalendarWidget QSpinBox {
width: 80px;
font-size: 12px;
background-color: #f0f0f0;
selection-background-color: #0078d7;
selection-color: white;
border: 1px solid #ccc;
border-radius: 4px;
color: #333;
}
QCalendarWidget QSpinBox::up-button {
subcontrol-origin: border;
subcontrol-position: top right;
width: 20px;
}
QCalendarWidget QSpinBox::down-button {
subcontrol-origin: border;
subcontrol-position: bottom right;
width: 20px;
}
QCalendarWidget QSpinBox::up-arrow {
width: 10px;
height: 10px;
}
QCalendarWidget QSpinBox::down-arrow {
width: 10px;
height: 10px;
}
QCalendarWidget QWidget {
alternate-background-color: #f0f0f0;
}
QCalendarWidget QAbstractItemView:enabled {
font-size: 12px;
selection-background-color: #0078d7;
selection-color: white;
background-color: white;
color: #333;
}
QCalendarWidget QWidget#qt_calendar_navigationbar {
background-color: #f8f8f8;
}
""")
# 更新标签样式
self.date_label.setStyleSheet("QLabel { color: #666; }")
# 更新按钮样式
self.close_btn.setStyleSheet("""
QPushButton {
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 12px;
font-size: 16px;
font-weight: bold;
color: #333;
}
QPushButton:hover {
background-color: #e0e0e0;
}
""")
self.today_btn.setStyleSheet("""
QPushButton {
background-color: #0078d7;
color: white;
border: none;
border-radius: 4px;
padding: 5px 10px;
}
QPushButton:hover {
background-color: #005a9e;
}
""")
self.clear_btn.setStyleSheet("""
QPushButton {
background-color: #f0f0f0;
color: #333;
border: 1px solid #ccc;
border-radius: 4px;
padding: 5px 10px;
}
QPushButton:hover {
background-color: #e0e0e0;
}
""")
self.insert_btn.setStyleSheet("""
QPushButton {
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
padding: 5px 10px;
}
QPushButton:hover {
background-color: #45a049;
}
""")
def on_theme_changed(self, is_dark):
"""主题切换槽函数"""
self.apply_theme()
if __name__ == "__main__":

@ -323,6 +323,11 @@ class WordStyleMainWindow(QMainWindow):
# 更新功能区下拉框样式
if hasattr(self, 'ribbon'):
self.update_ribbon_styles(is_dark)
# 更新日历组件样式
if hasattr(self, 'calendar_widget') and self.calendar_widget is not None:
# 日历组件有自己的主题管理机制,只需触发其主题更新
self.calendar_widget.apply_theme()
def update_ribbon_styles(self, is_dark):
"""更新功能区样式"""

Loading…
Cancel
Save