setStyleSheet via .qss file
-
mainwindow constructor:
QFile file(":/Darkeum.qss"); file.open(QFile::ReadOnly); QString styleSheet = QLatin1String(file.readAll()); setStyleSheet(styleSheet);Darkeum.qssis in the project folder, and I also add it to the.profile:DISTFILES += \ Darkeum.qssI am getting this error:
QIODevice::read (QFile, ":\Darkeum.qss"): device not openIf 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.qssis in the project folder, and I also add it to the.profile:DISTFILES += \ Darkeum.qssI am getting this error:
QIODevice::read (QFile, ":\Darkeum.qss"): device not openIf 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