Get default style sheets for different OS
-
I am developing a cross-platform application, and it looks way worse in Windows that in Ubuntu. This has to do only with the default style sheet for Windows vs the one for Ubuntu. Is there a way to obtain the OS-dependent style sheet that is applied to an application? I have tried to retrieve the application style sheet with:
QApplication app(argc, argv); qDebug() << "Style sheet: " << app.styleSheet();
But this produces an empty string (unless you have manually set it to something). My intention is to retrieve the Ubuntu style sheet and save it to a file (and add it to the resources list), so I can then load it for the application in both OS:
QApplication app(argc, argv); QFile file(":/ubuntu_style.qss"); file.open(QFile::ReadOnly); QString styleSheet = QLatin1String(file.readAll()); app.setStyleSheet(styleSheet);
Any ideas on how to get the default style sheet of the OS?
-
@apalomer
There is no in-built stylesheet. You do have to set it yourself. hence why it is empty initially. I do not think Qt supplies anything OS -specific (unless I am mistaken?). So just supply two files, and at runtime/compile-time (there are Qt#define
/#ifdef
s for the OS you are compiling for) read in/stipulate the one for the OS? -
@J-Hilk
You will probably tell me to "just go look and see", but so far I've never set any style (theme?) like this on any Qt app. So I guess I have been using "vanilla". Am I missing out? If I plan to release for Lin/Win/Mac, would end users be more pleased with such a style or with none? -
Is there any way to convert the
QStyle*
that is returned fromQStyleFactory::create
to a style sheet so I have access to the whole list of widgets and properties? I know I can apply my stylesheet modifying only certaint elements after theQStyleFactory::create
style is loaded.