2

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but I can't seem to get the external file loaded in QApplication. I tried a.setStyleSheet(":<prefix>/<alias>");
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(&stylesheet); a.setStyleSheet(ts.readAll());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.