diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp
index be4cef5e98..c8387c4e97 100644
--- a/src/Gui/Application.cpp
+++ b/src/Gui/Application.cpp
@@ -2100,8 +2100,25 @@ void Application::runApplication(void)
style = it->second;
}
if (!style.empty()) {
- QFile f(QLatin1String(style.c_str()));
- if (f.open(QFile::ReadOnly)) {
+ // Search for stylesheet in user, system and resources location
+ QString user = QString::fromUtf8((App::Application::getUserAppDataDir() + "Gui/Stylesheets/").c_str());
+ QString system = QString::fromUtf8((App::Application::getResourceDir() + "Gui/Stylesheets/").c_str());
+ QString resources = QLatin1String(":/stylesheets/");
+
+ QFile f;
+ if (QFile::exists(user + QLatin1String(style.c_str()))) {
+ f.setFileName(user + QLatin1String(style.c_str()));
+ }
+ else if (QFile::exists(system + QLatin1String(style.c_str()))) {
+ f.setFileName(system + QLatin1String(style.c_str()));
+ }
+ else if (QFile::exists(resources + QLatin1String(style.c_str()))) {
+ f.setFileName(resources + QLatin1String(style.c_str()));
+ }
+ else {
+ }
+
+ if (f.open(QFile::ReadOnly | QFile::Text)) {
mdi->setBackground(QBrush(Qt::NoBrush));
QTextStream str(&f);
qApp->setStyleSheet(str.readAll());
diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp
index ff893d920e..35b7cc0df8 100644
--- a/src/Gui/DlgGeneralImp.cpp
+++ b/src/Gui/DlgGeneralImp.cpp
@@ -171,7 +171,24 @@ void DlgGeneralImp::saveSettings()
hGrp->SetASCII("StyleSheet", (const char*)sheet.toByteArray());
if (!sheet.toString().isEmpty()) {
- QFile f(sheet.toString());
+ // Search for stylesheet in user, system and resources location
+ QString user = QString::fromUtf8((App::Application::getUserAppDataDir() + "Gui/Stylesheets/").c_str());
+ QString system = QString::fromUtf8((App::Application::getResourceDir() + "Gui/Stylesheets/").c_str());
+ QString resources = QLatin1String(":/stylesheets/");
+
+ QFile f;
+ if (QFile::exists(user + sheet.toString())) {
+ f.setFileName(user + sheet.toString());
+ }
+ else if (QFile::exists(system + sheet.toString())) {
+ f.setFileName(system + sheet.toString());
+ }
+ else if (QFile::exists(resources + sheet.toString())) {
+ f.setFileName(resources + sheet.toString());
+ }
+ else {
+ }
+
if (f.open(QFile::ReadOnly)) {
mdi->setBackground(QBrush(Qt::NoBrush));
QTextStream str(&f);
@@ -307,7 +324,7 @@ void DlgGeneralImp::loadSettings()
fileNames = dir.entryInfoList(filter, QDir::Files, QDir::Name);
for (QFileInfoList::iterator jt = fileNames.begin(); jt != fileNames.end(); ++jt) {
if (cssFiles.find(jt->baseName()) == cssFiles.end()) {
- cssFiles[jt->baseName()] = jt->absoluteFilePath();
+ cssFiles[jt->baseName()] = jt->fileName();
}
}
}
diff --git a/src/Mod/Start/StartPage/StartPage.py b/src/Mod/Start/StartPage/StartPage.py
index 59832d82f4..1de6f5eba3 100644
--- a/src/Mod/Start/StartPage/StartPage.py
+++ b/src/Mod/Start/StartPage/StartPage.py
@@ -299,9 +299,32 @@ def handle():
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("UseStyleSheet",False):
qssfile = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/MainWindow").GetString("StyleSheet","")
if qssfile:
- with open(qssfile, 'r') as f:
- ALTCSS = encode(f.read())
- HTML = HTML.replace("","")
+ # Search for stylesheet in user, system and resources locations
+ user = os.path.join(FreeCAD.getUserAppDataDir(), "Gui", "Stylesheets")
+ system = os.path.join(FreeCAD.getResourceDir(), "Gui", "Stylesheets")
+ resources = ":/stylesheets"
+
+ res = False
+ if QtCore.QFile.exists(os.path.join(user, qssfile)):
+ path = os.path.join(user, qssfile)
+ elif QtCore.QFile.exists(os.path.join(system, qssfile)):
+ path = os.path.join(system, qssfile)
+ elif QtCore.QFile.exists(os.path.join(resources, qssfile)):
+ res = True
+ path = os.path.join(resources, qssfile)
+ else:
+ path = None
+
+ if path:
+ if res:
+ f = QtCore.QFile(path)
+ if f.open(QtCore.QIODevice.ReadOnly | QtCore.QFile.Text):
+ ALTCSS = encode(QtCore.QTextStream(f).readAll())
+ else:
+ with open(path, 'r') as f:
+ ALTCSS = encode(f.read())
+
+ HTML = HTML.replace("","")
# turn tips off if needed