zhiyiYo / PyQt-Fluent-Widgets

A fluent design widgets library based on C++ Qt/PyQt/PySide. Make Qt Great Again.
https://qfluentwidgets.com
GNU General Public License v3.0
5.61k stars 541 forks source link

[Bug]: 切换应用程序主题颜色时无法切换至正确的颜色 #806

Closed JunNanLYS closed 7 months ago

JunNanLYS commented 7 months ago

What happened?

在设置主题颜色时应当切换至正确的颜色

Operation System

windows 11

Python Version

3.11

PyQt/PySide Version

PyQt 6.6.1

PyQt/PySide-Fluent-Widgets Version

1.5.2

How to Reproduce?

使用选项卡对应用程序主题颜色进行修改时,虽然themeMode发出了valueChanged信号,但是Fluent组件没有切换至正确的颜色。在config.json配置文件中手动修改主题颜色时可以正确切换至对应的主题颜色。

问题截图

Minimum code

import sys

from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout
from qfluentwidgets import (MSFluentWindow, FluentIcon, qconfig, SettingCardGroup, OptionsSettingCard)

class SettingInterface(QWidget):
    def __init__(self, parent):
        super().__init__(parent)
        self.setObjectName("SettingInterface")
        self.vLayout = QVBoxLayout(self)

        self.personalizationGroup = SettingCardGroup("Personalization", self)
        self.applicationTheme = OptionsSettingCard(
            title="Application theme",
            icon=FluentIcon.BRUSH,
            content="Set your application theme",
            configItem=qconfig.themeMode,
            texts=["Light", "Dark", "Auto"],
            parent=self.personalizationGroup
        )
        self.personalizationGroup.addSettingCard(self.applicationTheme)

        self.vLayout.addWidget(self.personalizationGroup)

class MainWindow(MSFluentWindow):
    def __init__(self):
        super().__init__(None)
        self.t1 = QWidget(self)
        self.t1.setObjectName("t1")
        self.addSubInterface(
            self.t1,
            FluentIcon.LABEL,
            "t1"
        )
        self.t2 = QWidget(self)
        self.t2.setObjectName("t2")
        self.addSubInterface(
            self.t2,
            FluentIcon.LABEL,
            "t2"
        )

        self.settings = SettingInterface(self)
        self.addSubInterface(
            self.settings,
            FluentIcon.SETTING,
            "Settings"
        )

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())
zhiyiYo commented 7 months ago

你需要捕获 applicationTheme.optionChanged 信号并调用 setTheme 来切换