setStyleSheet via .qss file
-
mainwindow constructor:
QFile file(":/Darkeum.qss"); file.open(QFile::ReadOnly); QString styleSheet = QLatin1String(file.readAll()); setStyleSheet(styleSheet);
Darkeum.qss
is in the project folder, and I also add it to the.pro
file:DISTFILES += \ Darkeum.qss
I am getting this error:
QIODevice::read (QFile, ":\Darkeum.qss"): device not open
If I am using the full file path it is working:
"C:/...../Darkeum.qss"
-
@ekato993 Use resources as I suggested or construct absolute path to the file at runtime (using relative paths is dangerous as you can see, they depend on current working directory): https://doc.qt.io/qt-5/qstandardpaths.html
-
mainwindow constructor:
QFile file(":/Darkeum.qss"); file.open(QFile::ReadOnly); QString styleSheet = QLatin1String(file.readAll()); setStyleSheet(styleSheet);
Darkeum.qss
is in the project folder, and I also add it to the.pro
file:DISTFILES += \ Darkeum.qss
I am getting this error:
QIODevice::read (QFile, ":\Darkeum.qss"): device not open
If I am using the full file path it is working:
"C:/...../Darkeum.qss"
@ekato993 said in setStyleSheet via .qss file:
QFile file(":/Darkeum.qss");
How should this path work?
If you want to use a relative path then do (I assume the file is next to the executable and that that folder is working directory):QFile file("Darkeum.qss");
But you should consider to use https://doc.qt.io/qt-5/resources.html
-
@ekato993 said in setStyleSheet via .qss file:
QFile file(":/Darkeum.qss");
How should this path work?
If you want to use a relative path then do (I assume the file is next to the executable and that that folder is working directory):QFile file("Darkeum.qss");
But you should consider to use https://doc.qt.io/qt-5/resources.html
-
@ekato993 Use resources as I suggested or construct absolute path to the file at runtime (using relative paths is dangerous as you can see, they depend on current working directory): https://doc.qt.io/qt-5/qstandardpaths.html
-
@ekato993 Use resources as I suggested or construct absolute path to the file at runtime (using relative paths is dangerous as you can see, they depend on current working directory): https://doc.qt.io/qt-5/qstandardpaths.html