新增了手动切换深浅色模式的功能

This commit is contained in:
2025-06-11 00:28:59 +08:00
parent 8d3408aac3
commit 07223f222b
5 changed files with 229 additions and 40 deletions

View File

@ -1,6 +1,8 @@
from pathlib import Path
from traceback import format_exc
from PySide6.QtWidgets import QMainWindow, QMessageBox, QFileDialog
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QMainWindow, QMessageBox, QFileDialog, QApplication, QWidget
from PySide6.QtGui import QGuiApplication
from matplotlib import use
from yaml import dump, load, FullLoader
@ -112,7 +114,16 @@ class MainWindow(QMainWindow, Ui_Signal_Label):
PublicFunc.__styleAllButton__(self, ButtonState)
try:
if QApplication.styleHints().colorScheme() == Qt.ColorScheme.Dark:
self.ui.checkBox_darkmode.setChecked(True)
else:
self.ui.checkBox_darkmode.setChecked(False)
except Exception as e:
PublicFunc.msgbox_output(self, Constants.MAINWINDOW_GET_DARKMODE_FAILURE + "" + format_exc(), Constants.TIPS_TYPE_ERROR)
# 绑定槽函数
self.ui.checkBox_darkmode.stateChanged.connect(self.set_dark_mode_status)
self.ui.pushButton_open.clicked.connect(self.__slot_btn_open__)
self.ui.pushButton_approximately_align.clicked.connect(self.__slot_btn_approximately_align__)
self.ui.pushButton_preprocess_BCG.clicked.connect(self.__slot_btn_preprocess__)
@ -351,4 +362,86 @@ class MainWindow(QMainWindow, Ui_Signal_Label):
for path in path_list:
if not path.exists():
path.mkdir(parents=True, exist_ok=True)
path.mkdir(parents=True, exist_ok=True)
def set_dark_mode_status(self):
try:
if self.ui.checkBox_darkmode.isChecked():
QApplication.styleHints().setColorScheme(Qt.ColorScheme.Dark)
else:
QApplication.styleHints().setColorScheme(Qt.ColorScheme.Light)
except Exception as e:
PublicFunc.msgbox_output(self, Constants.MAINWINDOW_DARKMODE_FAILURE + "" + format_exc(), Constants.MSGBOX_TYPE_ERROR)
return
try:
MainWindow.update_widget_style(self)
except RuntimeError:
pass
try:
if self.approximately_align is not None:
MainWindow.update_widget_style(self.approximately_align)
except RuntimeError:
pass
try:
if self.preprocess is not None:
MainWindow.update_widget_style(self.preprocess)
except RuntimeError:
pass
try:
if self.detect_Jpeak is not None:
MainWindow.update_widget_style(self.detect_Jpeak)
except RuntimeError:
pass
try:
if self.detect_Rpeak is not None:
MainWindow.update_widget_style(self.detect_Rpeak)
except RuntimeError:
pass
try:
if self.label_check is not None:
MainWindow.update_widget_style(self.label_check)
except RuntimeError:
pass
try:
if self.precisely_align is not None:
MainWindow.update_widget_style(self.precisely_align)
except RuntimeError:
pass
try:
if self.cut_PSG is not None:
MainWindow.update_widget_style(self.cut_PSG)
except RuntimeError:
pass
try:
if self.artifact_label is not None:
MainWindow.update_widget_style(self.artifact_label)
except RuntimeError:
pass
try:
if self.bcg_quality_label is not None:
MainWindow.update_widget_style(self.bcg_quality_label)
except RuntimeError:
pass
try:
if self.resp_quality_label is not None:
MainWindow.update_widget_style(self.resp_quality_label)
except RuntimeError:
pass
try:
if self.SA_label is not None:
MainWindow.update_widget_style(self.SA_label)
except RuntimeError:
pass
@staticmethod
def update_widget_style(mainWindow):
all_widgets = mainWindow.centralWidget().findChildren(QWidget)
# 迭代所有部件
for widget in all_widgets:
try:
widget.style().unpolish(widget)
widget.style().polish(widget)
widget.update()
except TypeError:
pass