Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to add a centralized stylesheet definition to a project?
rmam last edited by
I'm working on a project which uses custom stylesheets extensively. Instead of adding a stylesheet definition per widget, can anyone tell me if there is any way to store all stylesheet definitions in a single file and get Qt Creator and all widgets to follow them?
Stylesheets are cascading meaning you can set one style sheet to QApplication and it will
affect all Widgets in the application. This is much easier to manage than many stylesheets all over the widgets.
But this is only at runtime.
During Design time, you can set same style sheet on MainWindow ( or what ever is the top widget) and
all its children are affected but if you create a new form, then it wont automatically
get a/the stylesheet. I also missed that feature.
So yes, you can use one file and apply it exactly once but only run time.
Its more fiddle, fiddle when in Designer.
That said, the UI files are just xml files so its quite easy to use a cmdline tool like
and auto add a stylesheet for all UI files if its a must to see the right look in Designer
and then when "ready" strip all UI files for stylesheets and
only set via application so you can get the benefit of one file for all styles.
That said again ;), stylesheets was meant for smaller tweaks.
For a custom look, QStyle offer far better performance and absolute control.