Using PyQt, is there any way to change the stylesheet for every instance of a widget without having to manually change each widget's stylesheet.
Say, for instance, I wanted every pushbutton in my application to have red text. How would I do this without having to run button.setStyleSheet() for each button? Could there possibly be a way to change PyQt's stock button class?
Any help would be appreciated :)
Set the style sheet of your QApplication instance to change the style of specific widgets globally, e.g.:
GLOBAL_STYLE = """QPushButton {
color: red;
}"""
class MyApp(QMainWindow):
# your ui code here
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyleSheet(GLOBAL_STYLE)
main = MyApp()
main.show()
sys.exit(app.exec_())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With