How could Qt apply style from an external Qt Stylesheet file?

Say the user have its stylesheet named stylesheet.qss and is located in the application folder.

You could load the style sheet when starting the application, using the -stylesheet argument :

myapp->stylesheet = stylesheet.qss;

But this require your user to know how to start an application with arguments.

What you could also do is to add a settings dialog in your app, where the user can choose a stylesheet path.

You can then open this file, load the content, and set it to your application with QApplication::setStyleSheet() :

 QFile file("stylesheet.qss");
 file.open(QFile::ReadOnly);
 QString styleSheet = QLatin1String(file.readAll());

 qApp->setStyleSheet(styleSheet);

Qt is providing an example online which might be helpful.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)