Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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?

    P.S. This question is also asked in stack overflow


  • Moderators

    @apalomer if you want the same style across platforms you'll have to design your own or use fusion

    QApplication a(argc, argv);
    a.setStyle(QStyleFactory::create("Fusion"));
    

    IIRC Fusion is the default one for linux



  • @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/#ifdefs for the OS you are compiling for) read in/stipulate the one for the OS?


  • Moderators

    @apalomer if you want the same style across platforms you'll have to design your own or use fusion

    QApplication a(argc, argv);
    a.setStyle(QStyleFactory::create("Fusion"));
    

    IIRC Fusion is the default one for linux



  • @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 from QStyleFactory::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 the QStyleFactory::create style is loaded.



  • @apalomer
    No. Read through https://stackoverflow.com/questions/28841705/how-to-obtain-entire-qt-stylesheet-for-qmacstyle where someone would like to do this. Read through the comments below the accepted solution.


Log in to reply