Question

What I am trying to do I need to split my large style file to small style files because now it is hard to read the style file(qss file) and add new styling to it. after that i need to load those small qss files to apply them all

I am loading my Big file by calling function on main I have created

void Utilities::loadEnglishStyle()
{
    QFile file(":/EnglishClasses.qss");
    file.open(QFile::ReadOnly);
    QString StyleSheet = QLatin1String(file.readAll());
    qApp->setStyleSheet(StyleSheet);
    file.close();
}

I thought about split the big file, add the small files to the resources, open all of them by QFile and after that concatenate them all in one string but every time when adding new qss file i still need to do the same process again

Is there any efficient way to do this ?!!

Was it helpful?

Solution

Your approach sounds correct. The process is not as complex as it sounds. The only thing you need is to add the "smaller" qss file in the resources, under a specific prefix (eg. stylesheets), and then automatically load and concatenate all these files. Sample code follows:

QDir stylesheetsDir(":/stylesheets");
QFileInfoList entries = stylesheetsDir.entryInfoList();
QString completeStylesheet = "";
foreach (QFileInfo fileInfo, entries)
{
    QFile file(":/stylesheets/" + fileInfo.fileName(););
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
       continue;

    QTextStream in(&file);
    completeStylesheet += in.readAll()
}

OTHER TIPS

you means some API shoud add as:

QWidget::addStyleSheet(StyleSheet);
QWidget::clearStyleSheet(StyleSheet);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top