tags:

views:

86

answers:

1
+2  Q: 

CSS in Qt Creator

I can't find anything on this topic, is it possible to use CSS files in Qt or do I have to use setStyleSheet on every element I want to style?

I can't say its very maintainable if I have to write all the styles in quotes.

+4  A: 

You can use -stylesheet to specify a stylesheet on the command line. In addition, you could load your .qss file from a file or a resource and then call setStylesheet on your QApplication instance.

Kaleb Pederson
Thanks, but I can't seem to get the external file loaded in QApplication. I tried a.setStyleSheet(":<prefix>/<alias>");
Dennis
Once you've added the file as a resource you need to open the resource and read it into a string. You can start the process with: `QFile stylesheet(":<prefix>/<alias")` and then reading in the text. Perhaps: `stylesheet.open(QIODevice::ReadOnly); QTextStream ts( a.setStyleSheet(ts.readAll());`
Kaleb Pederson
awesome, it works.
Dennis