我的qss文件夹和qss在同一个目录,或者子目录
使用:
// 读取QSS文件
QFile file(":/qss/style.qss"); // 注意这里的路径可能需要根据你的项目结构进行调整
if (!file.exists()) {
qDebug() << "QSS file not found!";
} else if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Failed to open QSS file!";
} else {
QTextStream in(&file);
QString styleSheet = in.readAll();
h.setStyleSheet(styleSheet); // 应用到整个应用程序
// 或者 w.setStyleSheet(styleSheet); // 如果只想应用到主窗口
}