Reputation: 3
I found a QSS file online (http://tech-artists.org/forum/showthread.php?2359-Release-Qt-dark-orange-stylesheet) that I would like to use as the style in my app. I have been trying multiple different ways of importing this file into my program, but every time I run my program, it does not successfully open the file.
Currently I have the file saved as myStyle.qss in the same directory as my project. I have also been hearing about inserting the file into a qrc file. Is this necessary in order to open it, or just a convenient way of storing the file?
My code so far is:
QApplication a(argc, argv);
QFile file(":/myStyle.qss");
file.open(QIODevice::ReadOnly);
QString style(file.readAll());
a.setStyleSheet(style);
file.close();
Upvotes: 0
Views: 1131
Reputation: 18524
":/myStyle.qss"
it is path which uses for Qt
resource system. As you said, this file in the same directory, so try to set nornal path, "myStyle.qss"
, but be carefully because Qt
will search this file in the build directory, so you should place file in build directory.
But when your qss file will be done, then save it in the resources. There are many examples how to do this in the web (for example this. In this case you will need your current path ":/myStyle.qss"
Why do you need resource?
Resources are build into exe
file so you never lost this files, user can't delete it or rewrite. If user delete your qss
file, all your style will fail, so you should protect it.
Upvotes: 1