How to share a single style sheet across multiple .ui Qt Designer files
I'm a new developer, and maybe I'm going about this wrong, but I've got an application that is made up of a main window and multiple dock widgets and additional custom dialogs. Each of these windows (or is the right word here widgets?) has their own .ui file. I was hoping to set up a single style sheet that could be shared across all of them.
I can get it to work at runtime by putting all my styles in a single text (.qss) file, and loading that into a string, and then setting it on the QApplication object via setStyleSheet(). The problem with this solution is that those styles are not applied to what is seen in Qt Designer. Is there a way to share a single style sheet across multiple .ui files in Qt Designer?
Yes, and QApplication::setStyleSheet is a good way to do it. I think you just need to be a bit more specific about what you're doing and what's not working.
So all my styles are in file.qss, which is loaded at runtime by my app, and then I call mApp->setStyleSheet(stringLoadedQssFile);. Qt Designer, meanwhile, doesn't know about file.qss, nor does it load it up. Can I make Qt Designer load up this qss file and use its contents as the master style sheet for any given .ui file?
I am wondering the same thing. I find myself replicating the same style sheet settings across multiple forms which has been proven to be very difficult maintaining consistent styling across all my forms. Is there any way Designer can apply the stylesheets in the projects resource folder to the ui forms?
So we never did solve this problem. Our UI artist just runs the actual app to preview his changes. This sucks when there are .ui or code changes that need to recompile, and the app itself has a non-trivial initialization that can take 5-10 seconds. But he hasn't complained yet, so we haven't pursued it further.
I, too, am running into this problem.
The only work-around I've found is to apply the stylesheet to the root object in designer. Thankfully my project has <15 ui files, so this is manageable.
I found two bug reports about this issue, but no fix has been released yet, unfortunately:
Although nearly 8 years have passed since this topic was created, it appears that no progress was made in implementing this feature.
Here's a link to the relevant Qt Designer's bug report: Add support for external style sheets in Qt Widget Designer.