Copy all your styles into a file and rename it to something like stylesheet.qss
Then include it in your qrc
file as a new resource item. You can simply do this by editing your qrc
file, if you already have one. Refer documentation on how to add a new resource.
Then modify your code like this to read the content of the qss
file at run time and apply styles to your application.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QFile file(":/stylesheet.qss");
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
a.setStyleSheet(file.readAll());
file.close();
}
MainWindow w;
w.show();
return a.exec();
}
Note: when you do a change in the stylesheet.qss
, you have to compile the qrc
file for changes to take effect.