Hey everyone, I'm starting to use QT Designer and PySide6, and I have a question. In the code below, the button color and the button text color are not applied. No errors occur, but the color remains the same. What could be missing?
Please help me.
import sys
from PySide6.QtWidgets import QMainWindow, QApplication, QStyleFactory
from MainWindow_Dark_Light import Ui_MainWindow
import styles
class MainWindow(QMainWindow, Ui_MainWindow):
def init(self):
super(MainWindow, self).init()
self.setupUi(self)
self.btn_Dark.clicked.connect(self.set_dark)
self.btn_Light.clicked.connect(self.set_light)
def set_dark(self):
app = QApplication.instance()
styles.dark(app)
def set_light(self):
app = QApplication.instance()
styles.light(app)
app = QApplication()
# Definir o estilo "Fusion"
app.setStyle(QStyleFactory.create('Fusion'))
w = MainWindow()
w.show()
# styles.dark(app)
app.exec()
———————————————————————————-
from PySide6.QtGui import QPalette, QColor, QBrush
from PySide6.QtCore import Qt
def dark(app):
darkPalette = QPalette()
# darkPalette = QBrush()
darkPalette.setColor(QPalette.Window, QColor(53, 53, 53))
darkPalette.setColor(QPalette.WindowText, QColor(121, 121, 121))
darkPalette.setColor(QPalette.Button, QColor(0, 0, 0))
darkPalette.setColor(QPalette.ButtonText, QColor(255, 255, 255))
app.setPalette(darkPalette)
def light(app):
lightPalette = QPalette()
lightPalette.setColor(QPalette.Window, QColor(255, 255, 255))
lightPalette.setColor(QPalette.WindowText, QColor(0, 0, 0))
lightPalette.setColor(QPalette.Button, QColor(255, 255, 255))
lightPalette.setColor(QPalette.ButtonText, QColor(0, 0, 0))
app.setPalette(lightPalette)