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

setTheme() on Dialog Window Resets MainWindow StyleSheet #304

Closed rllysleepy closed 1 year ago

rllysleepy commented 1 year ago

Describe the bug When creating a new dialog window, setting the style will cause the stylesheets of main window to reset.

Environment 环境信息

To Reproduce See code.

Code 最小复现代码

import sys
from PyQt6.QtCore import *
from PyQt6.QtGui import *
from PyQt6.QtWidgets import *
from qfluentwidgets import *
from qframelesswindow import *

class dialog(QDialog, AcrylicWindow):
    def __init__(self):
        super().__init__()
        setTheme(Theme.DARK)

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        setTheme(Theme.DARK)
        container=QWidget()
        layout=QVBoxLayout()
        self.setStyleSheet("background-color: #303030;")
        button=PushButton("open new window")
        button.setStyleSheet("background-color: red;")
        button.clicked.connect(self.newDialog)

        container.setLayout(layout)
        layout.addWidget(button)
        self.setCentralWidget(container)

    def newDialog(self):
        newdialog=dialog()
        newdialog.show()

app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())

Expected behavior Stylesheet of main window should be left alone.

Screenshots If applicable, add screenshots to help explain your problem.

zhiyiYo commented 1 year ago

The scope of setTheme is global and cannot be applied separately to a component. If you want to apply a style to a component separately, you need to call FluentStyleSheet.DIALOG.apply(dialog, Theme.DARK)